Inheritance
Inheritance allows you to reuse common code and so has a profound effect on the way you implement your Python classes. It also allows you to organize your classes into a hierarchical arrangement. Classes toward the bottom of the hierarchy inherit from classes higher up (like a family tree). Thus, if you create a class, classB, that inherits behavior and attributes from another class, ClassA, then classB becomes the subclass of classA, and classA becomes the superclass of classB.
A subclass can override or create new behavior and attributes specific to its role. This is called specialization.
The Limits of InheritanceIt may look like one, but inheritance is no silver bullet. In fact, there are reasons to limit its use. Like all good ... |
Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.