Inheritance Examples
Inheritance is the most important aspect of object-oriented programming which simulates the real world concept of inheritance. It specifies that the child object acquires all the properties and behaviors of the parent object.
By using inheritance, we can create a class which uses all the properties and behavior of another class. The new class is known as a derived class or child class, and the one whose properties are acquired is known as a base class or parent class.
It provides re-usability of the code.
Example 1:
Output:
Calling child constructor
Calling child method
Calling parent method
Parent attribute : 200
Example 2:
dog barking
Animal Speaking
Multi Level Inheritance:
Multi-Level inheritance is possible in python like other object-oriented languages. Multi-level inheritance is archived when a derived class inherits another derived class. There is no limit on the number of levels up to which, the multi-level inheritance is archived in python.
Example 3:
dog barking
Animal Speaking
Eating bread...
Last updated