CSC148H5 Lecture Notes - Lecture 3: University Of Toronto Mississauga, Item Number, Init

79 views3 pages

Document Summary

Csc148h5s - introduction to computer science (winter 2016) Many times, a new class will have much in common with an existing class. Copying-and-pasting from the old class, and then making a few changes, is a bad idea. Allows a new class to specialize an existing class by specifying only what is different between the inherited class and original class. Class that inherits is called a subclass. Class that is inherited from is called a superclass. Let"s think about points and line segments. class point : class linesegment : You use instance variables to represent what the object has. class linesegment : def __init__ (self, p1, p2): self. p1 = p1 self. p2 = p2. To declare a class, you would start off with class name : To inherit from another class, add the superclass name in the class parameters class subclass (main_class): class indestructibleship (ship): They"re both kinds of buildings. class building : class house (building): class business (building):

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents