Today in this article I will show you OOP concepts in the C# language.
I have updated this article on my personal blog. you can read it
Inheritance With Example in Csharp.
Introduction
Real-world Example
A scientific calculator is an extended form of a calculator. Here calculator is the parent and scientific calculator is child object.
Programming Example
The process of acquiring the existing functionality of the parent and with the new added features and functionality of a child object.
What Inheritance is
Inheritance is one of the three foundational principles of Object-Oriented Programming (OOP) because it allows the creation of hierarchical classifications. Using inheritance you can create a general class that defines traits common to a set of related items. This class can then be inherited by other, more specific classes, each adding those things that are unique to it.
In the language of C#, a class that is inherited is called a base class. The class that does the inheriting is called the derived class. Therefore a derived class is a specialized version of a base class. It inherits all of the variables, methods, properties, and indexers defined by the base class and adds its own unique elements.
Example
Diagram
The following diagram shows the inheritance of a shape class. Here the base class is Shape and the other classes are its child classes. In the following program we will explain the inheritance of the Triangle class from the Shape class.