INHERITANCE IN PYTHON:
1. Inheritance is a key concept in Object-Oriented Programming.
2. Enables us to create a new class from an existing class.
3. The new class is a specialized version of the existing class and it inherits
all the non-private variables and methods of the existing class.
Its Benefits:
1) It represents real-world relationships well.
2) It provides reusability of a code. We don’t have to write the same code
again and again. Also, it allows us to add more features to a class
without modifying it.
3) It is transitive in nature, which means that if class B inherits from
another class A, then all the subclasses of B would automatically inherit
from class A.
Terminologies:
Superclass or parent class: the existing class.
Subclass or child class: the class inherits the superclass.
Syntax:
class ParentClass:
class ChildClass(ParentClass):
…
ex:
types :
1) single inheritance:
When a child class inherits from only one parent class.
Ex:
2) MULTIPLE INHERITANCE:
When a class is derived from more than one base class.
Syntax: Class Base1:
Body of the class
Class Base2:
Body of the class
Class Derived(Base1, Base2):
Body of the class
Ex: