Types of inheritance in Python
Now, that we are quite familiar with the terminologies like Parent class, and child class, now we are going to have a look at some of the different types of inheritance, and before that, we are simply going to understand how we can use inheritance in our programs.
First of all, Let’s have a look at a very simple program, which demonstrates to us how we can use inheritance in our program. The example is very dummy, but it can make things easy to understand for us.
Types of inheritance in Python
As you can see in the above program, there is a class ChildClass, which inherits from the class ParentClass. Notice the syntax of how we are implementing the inheritance. While we are defining the sub-class, we are writing the parent class in the brackets.
Here, due to the inheritance, the ChildClass object has access to the ParentClass method, as you can see in the example, which means that we can access that method with the child class object, without any modifications, which leads to code reusability. Do not worry about the syntax, since you would get used to it, once you get using it.
Now, that we have understood how we are implementing inheritance in our programs, now, Let’s have a look at some of the different types of inheritance here. Have a look at the list of different types of inheritance, and we are going to discuss some of the types here –
- Single Inheritance.
- Multilevel Inheritance.
- Multiple Inheritance.
- Hierarchical Inheritance.
- Hybrid Inheritance.