C# program for Single Inheritance

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:

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