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#

  1. Single Inheritance
  2. Hierarchical Inheritance
  3. Multi-level Inheritance
  4. Multiple Inheritances

1) Single Inheritance

In single inheritance only one base and one derived class is used.

Types of Inheritance in C# (1)

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.

Types of Inheritance in C# (2)

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.

Types of Inheritance in C# (3)

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.

Types of Inheritance in C# (4)

This is not possible directly in C#. So, that we need to implement it using "Interface".



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.