The following is an example of Single Inheritance in C#. In the example, the base class is Father and declared like the following code snippet −
class Father {
public void Display() {
Console.WriteLine("Display");
}
}Our derived class is Son and is declared below −
class Son : Father {
public void DisplayOne() {
Console.WriteLine("DisplayOne");
}
}Example
The following is the complete example to implement Single Inheritance in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyAplication {
class Demo {
static void Main(string[] args) {
// Father class
Father f = new Father();
f.Display();
// Son class
Son s = new Son();
s.Display();
s.DisplayOne();
Console.ReadKey();
}
class Father {
public void Display() {
Console.WriteLine("Display");
}
}
class Son : Father {
public void DisplayOne() {
Console.WriteLine("DisplayOne");
}
}
}
}Output
Display Display DisplayOne