Inheritance is one of the main feature of OOPS. It helps to reuse the code of one class into another by inheriting. Inherited class is called as ‘Base’ or ‘Parent’ class and inheriting class is called as ‘Derived’ or ’Child’ class. By inheriting, the child class can use the properties and functions of base class. This is just like a son/daughter getting some of the behavior from his/her parents. There are different types of inheritance.
- Single Inheritance
- Multi Level inheritance
- Multiple inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
A single derived class from single base class.
Multi Level inheritance
A child class is derived from another child class.The second child class will have all inheritable properties and functions of both base and first child classes.
A child class is derived from more than one base class. It is not possible to inherit multiple classes in C#. It is because there is a problem called Diamond Ring problem, which causes conflicts between members of classes. But to overcome the problem, Interfaces are introduced.
More than one child classes from single base class.
It is the combination of all the inheritance. As it is the combination of all inheritance, it include multiple inheritance also, so it’s not supported in C#.