C# Inheritance

Inheritance

Inheritance is the most important key features of object-oriented programming. It concept in which you declare parent classes and child classes. C# Inheritance allows you to declare a base class that provides specific functionality and to declare derived classes that either overrides the functionality. Inheritance takes properties of one class into another class. You can extend an existing class that reusability provides inheritance. Using inheritance you can reduce complexity in code that reusability promotes the object-oriented programming. C# Object.

In inheritance allows you to define a child class that reuse, extend or modify the behaviors and attributes which is declared in other class. In inheritance, the newly created class is the derived class or it a child class and the existing class is the base class or parent class.

Base class – the class whose members to be inherited into another class.

Derived class – the class that inherits the members of another class.

 The following are the 5 types of inheritance in C#.

1. Single Inheritance

2. Hierarchical Inheritance

3. Multilevel Inheritance

4. Multiple Inheritance

5. Hybrid Inheritance

C# basic course click on: C Sharp

1. Single Inheritance

In single inheritance, there is one base class and one derived class in Inheritance. In the following image, class A serves as a base class for the derived class B.

C# basic course click on: C Sharp

2. Hierarchical Inheritance

In that Hierarchical inheritance, there are multiple classes derived from one base class. Hierarchical inheritance used when there is a requirement of one class feature that is needed in multiple classes. In the following image A is a base class for the derived class B, C, and D.

C# basic course click on: C Sharp

3. Multilevel Inheritance

A multilevel inheritance one class is derived from another derived class. A derived class will be inheriting a base class. In the following image, class A serves as a base class for the derived class B, which is class B serves as a base class for the derived class C.

C# basic course click on: C Sharp

4. Multiple Inheritance

In C# Multiple Inheritance not supported, so we need to implement multiple inheritances using interfaces. It is one class can have more than one superclass and inherit features from all parent classes. In the following image, class C is derived from interface class A and class B.

C# basic course click on: C Sharp

5. Hybrid Inheritance

Any combination of more than one inheritance like Single Inheritance, Hierarchical Inheritance, and Multilevel Inheritance this called as Hybrid Inheritance. C# does not support hybrid inheritance; we can achieve hybrid inheritance only through Interfaces. 

C# basic course click on: C Sharp

Web API 2- .Net Core In depth In 5 Hours click on: https://www.udemy.com/web-api-2-net-core-in-depth-in-5-hrs-with-sagar-jaybhay/

Visit our website: https://www.expertwithsagarjaybhay.com/

sagar jaybhay

One thought on “C# Inheritance

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top