CSC148H5 Lecture Notes - Lecture 3: University Of Toronto Mississauga, Item Number, Init
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):