Parent Class (Super Class or Base Class): This class allows the reuse of its public properties in another class.
Child Class (Sub Class or Derived Class): This class inherits or extends the superclass.
A child class has all public attributes of the parent class.
class ParentClass: # attributes of the parent class class ChildClass(ParentClass): # attributes of the child class
super() as opposed to
self to access the parent class properties instead of the child class properties of the same name.
Types of Inheritance#
There is only one class extending from another class.
A class extends another class which itself extends another class.
A base class is extended by distinct classes depending on the requirements.
A class extends or is derived from more than one base class.
class ClassName(BaseClass, AnotherBaseClass, ...): def method() pass
Advantages of Inheritance#
Reusability, code modification, extensibility and data hiding.