Let us see the source code for the Single Inheritance program in C#. You may go through the theory of inheritance first.
Explanation: Inheritance in OOP means to derive some property of another Class. The following program Class B inherits Class A. Now, by only creating an object for Class B, you can access the properties of Class A.
C# Program to Illustrate Single Inheritance
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | using System; class A { public A() { Console.WriteLine("Class A Instantiated"); } } class B: A { public B() { Console.WriteLine("Class B Inherited Class A"); } } class Program { static void Main(string[] s) { new B(); } } |
Output:
Class A Instantiated
Class B Inherited Class A