Inheritance in C# With Example?
Let’s start with the concept Inheritance in C# with example, Inheritance is the concept in which one type (class/interface) derives data member and member functions from another type is called as inheritance. The type which derives the members from another type is called as derived type and the type from which derives is called as base type.
C# supports two types of inheritance:
- Implementation inheritance
- Interface inheritance
Implementation inheritance involves code from one class that is reused in another, while interface inheritance implies the inheritance of only the signatures of functions from one type to another.
Main advantage of inheritance is reusability of the code.Example: We have created two classes one is base class called ClsBase and other is Child class called ClsChild, this ClsChild class is derived from ClsBase Class. Now lets see the following code,