The process of inheriting the properties of a parent class into a child class is called inheritance. The existing class is called a base class or parent class, and the new class is called a subclass, child class, or derived class.
In this Python lesson, you will learn inheritance, the types of inheritance, the super() function, method overriding, method overloading, and MRO (Method Resolution Order).
In object-oriented programming, inheritance is an important concept. The main purpose of inheritance is code reusability: we can use an existing class to create a new class instead of writing it from scratch.
In inheritance, the child class acquires all the data members, properties, and methods of the parent class. A child class can also provide its own implementation of the parent class’s methods.
For example, in the real world, a Car is a type of Vehicle. We can create a Car class by inheriting the properties of a Vehicle class, such as wheels, color, fuel tank, and engine, and then add extra properties specific to a car. This is called an “is-a” relationship: a Car is a Vehicle.
Syntax
class BaseClass:
Body of base class
class DerivedClass(BaseClass):
Body of derived classCode language: Python (python)
Also, See
Table of contents
Types Of Inheritance
In Python, based on the number of child and parent classes involved, there are five types of inheritance:
- Single inheritance
- Multiple inheritance
- Multilevel inheritance
- Hierarchical inheritance
- Hybrid inheritance
Now let’s see each type in detail with an example.
Single Inheritance
In single inheritance, a child class inherits from a single parent class. There is one child class and one parent class.

Example
Let’s create one parent class called Vehicle and one child class called Car to implement single inheritance.
Output
Inside Vehicle class Inside Car class
The Car class doesn’t define vehicle_info(), but the car object can still call it because Car inherits it from Vehicle.
Multiple Inheritance
In multiple inheritance, one child class inherits from more than one parent class. There is one child class and multiple parent classes.

Example
Output
Inside Person class Name: Jessa Age: 28 Inside Company class Name: Google location: Atlanta Inside Employee class Salary: 12000 Skill: Machine Learning
In the above example, we created two parent classes, Person and Company. Then we created one child class, Employee, which inherits from both Person and Company. So an Employee object can use the methods of both parents.
Multilevel inheritance
In multilevel inheritance, a class inherits from a child class (a derived class). Suppose there are three classes A, B, and C. A is the superclass, B is the child class of A, and C is the child class of B. In other words, a chain of classes is called multilevel inheritance.

Example
Output
Inside Vehicle class Inside Car class Inside SportsCar class
In the above example, there are three classes: Vehicle, Car, and SportsCar. Vehicle is the superclass, Car is a child of Vehicle, and SportsCar is a child of Car. This is the chaining of classes.
Hierarchical Inheritance
In hierarchical inheritance, more than one child class is derived from a single parent class. In other words, there is one parent class and multiple child classes.

Example
Let’s create Vehicle as a parent class and two child classes, Car and Truck.
Output
This is Vehicle Car name is: BMW This is Vehicle Truck name is: Ford
Hybrid Inheritance
When inheritance combines two or more of the above types, it is called hybrid inheritance.

Example
Output
Inside Vehicle class Inside Car class Inside SportsCar class
Note: The above example combines hierarchical and multiple inheritance. The parent class Vehicle has two child classes, Car and Truck. This is hierarchical inheritance.
In addition, SportsCar inherits from two parent classes, Car and Vehicle. This is multiple inheritance.
Python super() function
In a child class, we can refer to the parent class by using the super() function. The super() function returns a temporary object of the parent class that allows us to call the parent class’s methods inside a child class method.
Benefits of using the super() function:
- We don’t need to remember or hard-code the parent class name to access its methods.
- We can use the
super()function in both single and multiple inheritance. - The
super()function supports code reusability, because we can extend a parent method instead of rewriting it.
Example
Output:
Jessa works at Google
In the above example, we create a parent class Company and a child class Employee. In the Employee class, we call the parent class method using the super() function.
Calling the Parent Constructor with super()
The most common use of super() is to call the parent class’s constructor (__init__()) from the child class constructor. This way, the parent initializes its own attributes, and the child only adds what is new.
Note: If a child class defines its own __init__(), the parent’s __init__() is not called automatically. You must call it explicitly with super().__init__().
Output:
Brand: BMW | Color: Black | Seats: 5
issubclass()
In Python, we can check whether a particular class is a subclass of another class using the built-in function issubclass(). This function returns True if the given class is a subclass of the specified class. Otherwise, it returns False.
Syntax
issubclass(class, classinfo)Code language: Python (python)
Where,
class: The class to be checked.classinfo: A class, a type, or atupleof classes and types. If it is a tuple, the function returnsTruewhen the class is a subclass of any of them.
Example
Output:
True False False True True
Note: A class is considered a subclass of itself, which is why the last line returns True. To check whether an object (not a class) belongs to a class, use Python isinstance().
Method Overriding
In inheritance, all members of the parent class are available in the child class by default. If the parent class’s implementation of a method doesn’t suit the child class, the child class can redefine that method with its own behavior. This concept is called method overriding.
When a child class defines a method with the same name as a method in its superclass, the child’s method is said to override the parent’s method. When you call that method on a child object, Python runs the child’s version.

Example
Output:
max speed is 200 Km/Hour
In the above example, we create two classes: Vehicle (parent class) and Car (child class). Car extends Vehicle, so all properties of the parent class are available in the child class. In addition, the child class redefines the method max_speed().
Extending instead of replacing: An overriding method can still run the parent’s version by calling it with super(), and then add its own behavior.
Output:
Max speed is 100 km/h Car max speed is 200 km/h
Method Overloading
Method overloading means defining multiple methods with the same name but different parameters. Languages like Java and C++ support it directly, but Python does not. If you define two methods with the same name in a class, the second definition simply replaces the first.
Output:
6 TypeError: Calculator.add() missing 1 required positional argument: 'c'
Instead, Python achieves the same result with default arguments or variable-length arguments (*args), so a single method can handle different numbers of arguments.
Output:
5 15 30 16 24
Method Resolution Order in Python
In Python, the Method Resolution Order (MRO) is the order in which Python looks for a method or attribute. Python first searches the class itself, then its parent classes in the order we listed them while inheriting.
This order is also called the linearization of a class, and the set of rules that produces it is called the MRO. The MRO plays an essential role in multiple inheritance, because the same method may be found in multiple parent classes.
In multiple inheritance, Python follows this search order:
- First, it searches the current class. If the method is not found, it searches the parent classes in the order they were specified while inheriting (left to right).
- A parent class is searched only after all of its child classes have been searched. Python computes this order using the C3 linearization algorithm.
- To see the MRO of a class, use either the
__mro__attribute or themro()method.
Example
Output:
In class C [<class '__main__.C'>, <class '__main__.B'>, <class '__main__.A'>, <class 'object'>]
In the above example, we create three classes: A, B, and C. Class B inherits from A, and class C inherits from B and A. When we create an object of class C and call the process() method, Python looks for process() in class C itself first.
If it’s not found there, Python searches the parent classes B and then A, because C is defined as C(B, A). The search always goes from left to right. Every class ultimately inherits from Python’s built-in object class, which is why it appears last.
The diamond problem: In the following example, D inherits from B and C, and both inherit from A. The MRO makes sure A is searched only once, after both B and C.
Output:
In class B ['D', 'B', 'C', 'A', 'object']
Summary
- Inheritance lets a child class reuse the attributes and methods of a parent class.
- Python supports single, multiple, multilevel, hierarchical, and hybrid inheritance.
- Use
super()to call parent methods, especially the parent’s__init__(). - Use
issubclass()to check class relationships andisinstance()to check objects. - Method overriding lets a child class replace or extend a parent method.
- Python doesn’t support classic method overloading. Use default arguments or
*argsinstead. - The MRO decides which method runs when several classes define it. Check it with
ClassName.mro().
