This code demonstrates the use of single inheritance in C#. It the program there are two classes X and Y.
Y is extending X here through inheritance. Each of these two classes have there own constructors, but we are passing the value to the base class constructor(X()) through the
'base' keyword.
class X
{
int a, b;
public X(int a1, int b1)
{
a = a1;
b = b1;
Console.WriteLine("a={0}b={1}", a, b);
}
}
//Y extending the base class X
class Y:X
{
public Y(int n, int m):base(n,m)
{
Console.WriteLine("n={0}m={1}",n,m);
}
}
class MainClass
{
static void Main(string[] args)
{
Y o = new Y(10,20);
}
}
OUTPUT a=10b=20
n=10m=20