Types of Inheritance in Python (original) (raw)

Last Updated : 9 Oct, 2025

Inheritance is a key concept in object-oriented programming that allows one class (child/derived) to inherit the properties and methods of another class (parent/base). This promotes code reusability and improves maintainability. Here we a going to see the types of**inheritance in Python.

Types of inheritance Python

Types of inheritance

Types of Inheritance in Python

Types of Inheritance depend upon the number of child and parent classes involved. There are four types of inheritance in Python:

**Single Inheritance

Single inheritance enables a derived class to inherit properties from a single parent class, thus enabling code reusability and the addition of new features to existing code.

SingleInheritance

Single Inheritance

**Example:

Python `

Base class

class Parent: def func1(self): print("This function is in parent class.")

Derived class

class Child(Parent): def func2(self): print("This function is in child class.")

Driver code

obj = Child() obj.func1() obj.func2()

`

Output

This function is in parent class. This function is in child class.

**Explanation:

**Multiple Inheritance

When a class can be derived from more than one base class this type of inheritance is called multiple inheritances. In multiple inheritances, all the features of the base classes are inherited into the derived class.

MultipleInheritance

Multiple Inheritance

**Example:

Python `

Base class 1

class Mother: mothername = ""

def mother(self):
    print(self.mothername)

Base class 2

class Father: fathername = ""

def father(self):
    print(self.fathername)

Derived class

class Son(Mother, Father): def parents(self): print("Father :", self.fathername) print("Mother :", self.mothername)

Driver code

s1 = Son() s1.fathername = "RAM" s1.mothername = "SITA" s1.parents()

`

Output

Father : RAM Mother : SITA

**Explanation:

**Multilevel Inheritance

In multilevel inheritance, features of the base class and the derived class are further inherited into the new derived class. This is similar to a relationship representing a child and a grandfather.

MultilevelInheritance

Multilevel Inheritance

**Example:

Python `

Base class

class Grandfather: def init(self, grandfathername): self.grandfathername = grandfathername

Intermediate class

class Father(Grandfather): def init(self, fathername, grandfathername): self.fathername = fathername # Call the constructor of Grandfather Grandfather.init(self, grandfathername)

Derived class

class Son(Father): def init(self, sonname, fathername, grandfathername): self.sonname = sonname # Call the constructor of Father Father.init(self, fathername, grandfathername)

def print_name(self):
    print('Grandfather name :', self.grandfathername)
    print('Father name :', self.fathername)
    print('Son name :', self.sonname)

Driver code

s1 = Son('Prince', 'Rampal', 'Lal mani') print(s1.grandfathername) s1.print_name()

`

Output

Lal mani Grandfather name : Lal mani Father name : Rampal Son name : Prince

**Explanation:

**Hierarchical Inheritance

When more than one derived class are created from a single base this type of inheritance is called hierarchical inheritance. In this program, we have a parent (base) class and two child (derived) classes.

HierarchicalInheritance

Hierarchical Inheritance

**Example:

Python `

Base class

class Parent: def func1(self): print("This function is in parent class.")

Derived class 1

class Child1(Parent): def func2(self): print("This function is in child 1.")

Derived class 2

class Child2(Parent): def func3(self): print("This function is in child 2.")

Driver code

object1 = Child1() object2 = Child2()

object1.func1() object1.func2() object2.func1() object2.func3()

`

Output

This function is in parent class. This function is in child 1. This function is in parent class. This function is in child 2.

**Explanation:

Hybrid Inheritance

Hybrid inheritance is a combination of more than one type of inheritance. It uses a mix like single, multiple, or multilevel inheritance within the same program. Python's method resolution order (MRO) handles such cases.

HybridInheritance

Hybrid Inheritance

**Example:

Python `

Base class

class School: def func1(self): print("This function is in school.")

Derived class 1 (Single Inheritance)

class Student1(School): def func2(self): print("This function is in student 1.")

Derived class 2 (Another Single Inheritance)

class Student2(School): def func3(self): print("This function is in student 2.")

Derived class 3 (Multiple Inheritance)

class Student3(Student1, School): def func4(self): print("This function is in student 3.")

Driver code

obj = Student3() obj.func1() obj.func2()

`

Output

This function is in school. This function is in student 1.

**Explanation: