Introduction
Inheritance means acquiring the features and behaviors of a class from another class. It is a parent-child relationship. Using the Inheritance methodology, you can create a new class using the existing one. It is also referred to as the reusability of the code. So when you use Inheritance, you can reuse the code repeatedly.
In Inheritance, the Main class is called the base class, superclass, or parent class, and the new class created from the existing class is called the child class or subclass and derived class. We normally talk in terms of the base class and derived class.
The basic structure of Inheritance in C#
Here is the basic structure of inheritance. In this below code example, the ParentClass is a base class, and the ChildClass is a derived class from the ParentClass. The followed by base class name is the syntax used to derive a class from a base class.
class ParentClass
{
// Class members for ParentClass can be added here.
}
class ChildClass : ParentClass
{
// Class members for ChildClass can be added here.
}
Why do we use inheritance?
The answer is reusability. One of the key features of a modern programming language is code reusability. Multiple applications and programs can use a piece of code written by one developer if it provides the same functionality. It not only saves time but also reduces the size of the code. That helps program maintainability and improves reusability.
For example, say you have created a Calculator class that has the functionality of adding, subtracting, dividing, and multiplying. Now, other programs implement an advanced calculator with conversion functionality and advanced calculations with basic functionality; they can derive their classes from the Calculator class.
Types of inheritance
There are many types of Inheritance. I will explain all of them one by one.
Single Inheritance
Single Inheritance means a single base class is implemented by a single derived class called Single Inheritance. Here only one parent class and one derived class.

Example
class ParentClass
{
public void Run()
{
Console.WriteLine("This is parent’s Run method");
}
public void Walk()
{
Console.WriteLine("This is parent’s Walk method");
}
}
class ChildClass : ParentClass
{
public void Eat()
{
Console.WriteLine("This is the child’s Eat Method");
}
}
Here I am using single inheritance using a single base class.
Multilevel Inheritance in C#
When you create a derived class which inherited from another derived class or, in simple words, if a class is created by using another derived class and this type of implementation is called multilevel Inheritance.



Saeed AhmadvandPosted Dec 13, 2018, 12:09 PM
Good job...
Yaduveer SainiPosted Oct 16, 2015, 5:38 AM
Good Job Sir...keep it up
Banketeshvar NarayanPosted Oct 16, 2015, 3:34 AM
Great job.. Keep it up!
Mukesh KumarPosted Oct 2, 2015, 9:54 AM
thanks
Nilesh JadavPosted Oct 2, 2015, 9:10 AM
Nice work sir
Santhakumar MunuswamyPosted Oct 2, 2015, 9:09 AM
Good Article