Let us see the source code for C# multilevel inheritance program. You may go through the theory first by clicking the link below.
Explanation: In the following program, Class B inherits A Class C inherits B through which Class C can inherit the property of class A. So, only by creating a single object that is only for Class C, you can access the properties of Class A and B.
C# Program for Multilevel Inheritance
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 26 27 28 29 30 31 32 33 | using System; class A { public A() { Console.WriteLine("Class A Instantiated"); } } class B: A { public B() { Console.WriteLine("Class B Inherited Class A"); } } class C: B { public C() { Console.WriteLine("Class C Inherited Class A &B"); } } class Program { static void Main(string[] s) { C c = new C(); } } |
Output: