Saturday, February 8, 2020

Types of Inheritance in Python

Types Of Inheritance In Python

As we have discussed in this tutorial, that Inheritance is one of the object-oriented programming concepts. Inheritance enables classes to share and reuse the code among themselves. We can divide inheritance into different categories. Python supports the following types of inheritance,

  1. Single Inheritance
  2. Multiple Inheritance
  3. Multilevel Inheritance
  4. Hierarchical Inheritance
  5. Hybrid Inheritance

Single Inheritance

Single Inheritance is the simplest model of inheritance with the parent-child relationship.

Single Inheritance Model
Single Inheritance

Multiple Inheritance

Multiple inheritance model allows a child class to have more than one parent class.

Multiple Inheritance Model
Multiple inheritance model 

Multilevel Inheritance

Multilevel inheritance model enables to create subclasses of a subclass, it means a class may have grandparent classes.

multi-level inheritance model
Multi-level inheritance Model

Hierarchical inheritance

The hierarchical inheritance model allows declaring more than one subclass of a superclass.

Hybrid inheritance

Hybrid inheritance is a complex inheritance model, which is created when more than one model of inheritance is used to create the class hierarchy. In the diagram below, this is a mixture of multiple and hierarchical inheritance models.
Hybrid Inheritance model
Hybrid Inheritance model

Let's consider the following example,

Try Yourself: