---
title: "What is inheritance and how does it support code reuse?"  
description: "What is inheritance and how does it support code reuse?"  
author: "Steilla Mitchel"  
published: 2023-06-21  
updated: 2023-06-25  
canonical: https://www.mindstick.com/forum/158814/what-is-inheritance-and-how-does-it-support-code-reuse  
category: "oops"  
tags: ["c#", "java", "oops", "inheritance", "programming language"]  
reading_time: 2 minutes  

---

# What is inheritance and how does it support code reuse?

What is [inheritance](https://www.mindstick.com/articles/13095/inheritance-and-its-types) and how does it [support](https://yourviews.mindstick.com/view/286/modi-support-for-sportsperson) [code reuse](https://www.mindstick.com/forum/159020/explain-the-concept-of-traits-in-rust-and-how-they-enable-code-reuse-and-polymorphism)?

## Replies

### Reply by Aryan Kumar

Inheritance is a mechanism in object-oriented programming (OOP) that allows a new class to inherit the properties and methods of an existing class. This means that the new class can use the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) that is already written in the existing class, without having to reimplement it. This can save time and effort, and it can also help to ensure that the code is implemented consistently.

For example, let's say we have a `Vehicle` class with a method called `start()`. This method starts the vehicle. We could then have a `Car` class that inherits from the `Vehicle` class. The `Car` class could use the `start()` method from the `Vehicle` class, without having to reimplement it.

Inheritance can also be used to support code reuse in more complex ways. For example, we could have a `Shape` class with a method called `draw()`. This method draws the shape. We could then have subclasses of `Shape` that represent specific types of shapes, such as circles, squares, and triangles. These subclasses could inherit the `draw()` method from the `Shape` class, but they could also override the `draw()` method to provide their own implementation. This would allow each subclass to draw its own type of shape in a unique way.

Inheritance is a powerful tool that can be used to achieve greater code reuse in OOP. It allows programmers to create new classes that are based on existing classes, without having to reimplement the code that is already written. This can save time and effort, and it can also help to ensure that the code is implemented consistently.

Here are some of the benefits of inheritance:

- **Code reuse:** Inheritance allows for greater code reuse by allowing new classes to inherit the properties and methods of existing classes.
- **Flexibility:** Inheritance can be used to support code reuse in complex ways, such as by allowing subclasses to override the methods of their superclasses.
- **Abstraction:** Inheritance can be used to hide implementation details from the user, which can make the code more understandable and maintainable.


---

Original Source: https://www.mindstick.com/forum/158814/what-is-inheritance-and-how-does-it-support-code-reuse

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
