C# program for Multilevel Inheritance

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

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: