OBJECTSChapter 8 · Objects and Classes
Inheritance
A class can inherit from another: class Comet(SpaceObject): gets every method of SpaceObject for free. Override a method by defining it again in the child, and call the parent's version with super(). isinstance(obj, SomeClass) checks the type, and it counts parent classes too.
Worked example
How it reads
Comet(SpaceObject)means a Comet is a SpaceObjectsuper().__init__(name)runs the parent setup before adding more- Overriding
describereplaces it, andsuper().describe()still reaches the original

Cloud tip: Use inheritance for a true "is a" relationship. When one object merely uses another, keep it as an attribute instead.


