What is Inheritance?
Inheritance is a very important property in Object-Oriented Programming. Inheritance is the process of specifying a new class with small changes to an already present class. The new class is known as derived or child class and the one from which it acquires properties is known as Parent or base class.
To get in-depth knowledge of Python, take Python Online Training.
The syntax for Python Inheritance
Body of base class
Class DerivedClass (BaseClass):
Body of derived class
Advantages of Inheritance:
- It indicates real-time relationships properly.
- Using Inheritance, the reusability of code is possible. There is no need to write a program repeatedly. It also enables us to add more properties to a class without changing it.
- It is transitive in nature, which means if class B inherits from class A, then all the subclasses of B can instantly inherit form class A.
Learn How to code in Python?
Types of Inheritance:
There are five types of Inheritance
- Single Inheritance - If a child class acquires properties from only a single parent class, it is known as Single inheritance.
- Multiple inheritance - If a child class acquires properties from different parent classes, it is known as Multiple inheritance. Python uses multiple inheritance, we can define all parent classes as comma separated list in braces.
- Hierarchical Inheritance - If we have a child and grandchild relationship, then it is known as Hierarchical Inheritance.
- Hybrid Inheritance - In this, more than one derived class are created from one base.
- Multilevel inheritance - This type merges more than single form of inheritance. Usually, it is a combination of more than one type of inheritance.
I hope you got an overview of the Inheritance concept in Python. Follow my articles to get more updates on Python Programming Language.
Upgrade your career by taking Python Training.