Inheritance in Python
Inheritance in Python:
Inheritance in Python is the capability of one class to derive or inherit the properties from another class. In inheritance, the child class acquires the properties and can access all the data members and functions defined in the parent class. A child class can also provide its specific implementation to the functions of the parent class.
- Class A:
Benefits of Inheritance:
- Reusability of code.
- We can use the features of the other class, without modifying it.
- It is transitive in nature i.e. A->B->C == A->C and B->C.
Different forms of Inheritance:
- Single inheritance: When a child class inherits from only one parent class, it is called single inheritance.
- Multiple inheritance: When a child class inherits from multiple parent classes, it is called multiple inheritance
- Multilevel inheritance: When we have a child and grandchild type relationship.
- Hierarchical inheritance More than one derived classes are created from a single parent.
- Hybrid inheritance: This form combines more than one form of inheritance. Basically, it is a mixture of more than one type of inheritance.