Python Tutorial
About Lesson

In this Python lesson we want to learn about Python Hierarchical Inheritance, in python object oriented programming When more than one derived classes are created from a single base class that is called hierarchical inheritance.

 

 

Now let’s take a look at this image.

Python Hierarchical Inheritance
Python Hierarchical Inheritance

 

If you see in the image, we have four classes, Class A is our base or parent class, we have another three classes and all of them are extending from just one base class, as i have already said When more than one derived classes are created from a single base class that is called hierarchical inheritance. now there is a relationship between Class A and three derived classes(B, C, D), but there is no relationship between the derived classes, it means that we have a relationship between base class and derived classes, but there is no relationship between derived classes, for example we don’t have any relationship between Class B, Class C and Class D.

 

 

 

Now let’s create practical example in Python Hierarchical Inheritance

 

In the example we have three python classes, class Animal is our base class and we have two more classes that are inheriting from just one base class. we have relationship between Class Animal and Class Cat, also between Class Animal and Class Dog, but there is no relationship between Class Cat and Class Dog.

 

 

 

Run the code and this is the result.

Python Inheritance Type
Python Inheritance Type

 

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found