---
title: "Importance of the Inheritance"  
description: "In object oriented programming inheritance most important concepts of the programming language which is very useful and easy to use.  When to use: You"  
author: "Royce Roy"  
published: 2016-07-23  
updated: 2018-03-16  
canonical: https://www.mindstick.com/blog/11191/importance-of-the-inheritance  
category: "oops"  
tags: ["oops", "inheritance"]  
reading_time: 2 minutes  

---

# Importance of the Inheritance

In object [oriented programming](https://www.mindstick.com/forum/162/object-oriented-programming-oop-s) [inheritance](https://www.mindstick.com/articles/13095/inheritance-and-its-types) most important concepts of the [programming language](https://www.mindstick.com/articles/329035/5-most-in-demand-programming-languages-to-consider-for-your-app-development-in-2022) which is very useful and easy to use.\

**When to use:** **You can reuse the code whenever needed from the existing class, like method you can inherit and use it. You want to global change by [base class](https://www.mindstick.com/blog/116/base-class-initilization).**

##### For Example:

Create the [class name](https://www.mindstick.com/forum/12871/how-to-get-class-name) as SampleInheritanceParent

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace OopsConcepts{    class SampleParentInhertiance    {        string str = string.Empty;        public SampleParentInhertiance()        {            Console.WriteLine("Call Parent class the construtor");        }        public SampleParentInhertiance(string name)        {            str = name;            Console.WriteLine("str");         }        public int add(int x, int y)        {            return x + y;        }        public double mul(double a, double b)        {            return a * b;        }        public void display()        {            Console.WriteLine("call display method");        }     }}
```

Create the another class name as SampleInheritanceChild

\

**Note:** If you notice that we can inherit the SampleInheritanceChild:

\

SampleParentInhertiance

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace OopsConcepts{    class SampleInheritanceChild:SampleParentInhertiance    {        public SampleInheritanceChild()         {            Console.WriteLine("Call child class constructor");        }        public SampleInheritanceChild(string str2)        {            Console.WriteLine("Child class constructor call2");        }        public int sub(int w,int z)        {                    return w-z;                    }     }}
```

In last create another class with main [method name](https://www.mindstick.com/forum/33583/selector-creation-with-method-name-and-parameter) as

\
SampleInheritanceTest and create object and call it

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace OoopsConcepts{    class SampleInheritanceTest    {        static void Main(string[] args)        {            SampleInheritanceChild sc = new SampleInheritanceChild();            Console.WriteLine(sc.sub(10, 5));            Console.WriteLine(sc.mul(15, 5));            Console.WriteLine(sc.add(25, 5));            sc.display();           // Console.WriteLine(sc.display(1));             Console.ReadLine();        }    }}
```

##### Output:

Call Parent class the constructor

Call [child class](https://www.mindstick.com/forum/159389/how-to-remove-child-class-from-active-div) constructor

5

75

30

Call display method

**Why are use Interface**

Interface most powerful programming tool because they set to separate

\

[definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat) from their [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp)

- Interface are suitable in which when we unrelated object provide different functionalities.

- Interface is most reliable from base class because you can define a single implementation that can be implement multiple interface

---

Original Source: https://www.mindstick.com/blog/11191/importance-of-the-inheritance

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
