Types of Inheritance in C#

In this article, we will find out about Types of Inheritance in C# with its definition, syntax and so forth.

As we realize that by utilizing of Inheritance – we can make a new class with the use of an existing class, in light of the necessity, Inheritance can be utilized to oversee more than one base classes or beyond what one determined class can acquire the highlights of the base class. For that, there various kinds of Inheritances upheld by the C# programming language.

Kinds of Inheritance

Here, are the accompanying kinds of inheritance utilized in C#:

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

1) Single Inheritance

In single inheritance, just one base and one determined class are utilized.

Types of Inheritance in C#

Syntax:

    class A
    {
	    ...
    }

    class B : A
    {
	    ...
    }

2) Hierarchical Inheritance

In various levelled inheritance, we utilize one base class and different inferred classes. It implies one base class can be acquired by numerous inferred classes.

Types of Inheritance in C#

Syntax:

    class A
    {
	    ...
    }

    class B : A
    {
	    ...
    }
    class C : A
    {
	    ...
    }

    class D : A
    {
	    ...
    }

3) Multi-level Inheritance

In staggering inheritance, we utilize one base class is acquired by determined class and afterwards, we acquire inferred class further by another inferred class.

Types of Inheritance in C#

Syntax:

class A
{
	...
}

class B : A
{
	...
}
class C : B
{
	...
}

4) Multiple Inheritances

In various inheritance, we utilize more than one base class are acquired by one determined class.

Types of Inheritance in C#

This is unimaginable legitimately in C#. Along these lines, we have to execute it utilizing “Interface“.

Leave a Comment

error: Alert: Content is protected!!