Home »
.Net
Types of Inheritance in C#
In this article, we are going to learn about Types of Inheritance in C# with its definition, syntax etc.
Submitted by IncludeHelp, on April 03, 2018
Prerequisite: Inheritance in C#.
As we know that by using of Inheritance - we can create new class with functionality of existing class, based on the requirement, Inheritance can be used to manage more than one base classes or more than one derived classes can inherit the features of base class. For that, there different types of Inheritances supported by the C# programming language.
Types of Inheritance
Here, are the following types of inheritance used in C#
- Single Inheritance
- Hierarchical Inheritance
- Multi-level Inheritance
- Multiple Inheritances
1) Single Inheritance
In single inheritance only one base and one derived class is used.
Syntax:
class A
{
...
}
class B : A
{
...
}
2) Hierarchical Inheritance
In hierarchical inheritance, we use one base class and multiple derived classes. It means one base class can be inherited by multiple derived classes.
Syntax:
class A
{
...
}
class B : A
{
...
}
class C : A
{
...
}
class D : A
{
...
}
3) Multi-level Inheritance
In multi-level inheritance, we use one base class is inherited by derived class and then we inherit derived class further by another derived class.
Syntax:
class A
{
...
}
class B : A
{
...
}
class C : B
{
...
}
4) Multiple Inheritances
In multiple inheritance, we use more than one base class are inherited by one derived class.
This is not possible directly in C#. So, that we need to implement it using "Interface".