---
title: "Inheritance in Python"  
description: "Inheritance in Python"  
author: "Prakash nidhi Verma"  
published: 2018-06-26  
updated: 2023-05-03  
canonical: https://www.mindstick.com/interview/23444/inheritance-in-python  
category: "python"  
tags: ["python"]  
reading_time: 2 minutes  

---

# Inheritance in Python

Inheritance allows for one class to gain all the attributes and methods of another class. code reusability increase in Inheritance. it makes easier to create and maintain an application. The classfrom which we are inheriting is known as super-class and the class that is inherited is called a child class.

Type of Inheritance in Python :

- Single Inheritance

- Multi-level inheritance

- Hierarchical inheritance

- Multiple inheritance

## Answers

### Answer by Aryan Kumar

In Python, inheritance is the process of creating a new class that is a modified version of an existing class. The new class, called the child class or subclass, inherits the properties and methods of the existing class, called the parent class or superclass.

To create a subclass in Python, you define a new class and specify the name of the parent class in parentheses after the class name:

```python
class ParentClass:
   def method1(self):
       print("Parent method 1")
   def method2(self):
       print("Parent method 2")
class ChildClass(ParentClass):
   def method2(self):
       print("Child method 2")
```

In this example, we define a parent class called **ParentClass** with two methods **method1()** and **method2()**. We then define a child class called **ChildClass** that inherits from **ParentClass** using the syntax **class ChildClass(ParentClass):**.

The **ChildClass** overrides the implementation of **method2()** from **ParentClass** by defining its own implementation of the method. It does not modify the implementation of **method1()** from the parent class.

To create an instance of the **ChildClass**, you simply call the constructor of the class:

```python
child = ChildClass()
```

In Python, you can also use the **super()** function to call a method in the parent class from within a method in the child class:

```python
class ChildClass(ParentClass):
   def method2(self):
       super().method2()  # call the parent class implementation of method2
       print("Child method 2")
```

In this example, the **method2()** of the **ChildClass** calls the parent class implementation of the method using the **super()** function before printing its own message.

\

### Answer by Prakash nidhi Verma

Inheritance allows for one class to gain all the attributes and methods of another class. code reusability increase in Inheritance. it makes easier to create and maintain an application. The classfrom which we are inheriting is known as super-class and the class that is inherited is called a child class.

Type of Inheritance in Python :

- Single Inheritance

- Multi-level inheritance

- Hierarchical inheritance

- Multiple inheritance


---

Original Source: https://www.mindstick.com/interview/23444/inheritance-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
