class GrandFather : Object
public int Id { get; set; }
public string Name { get; set; }
public virtual void Show()
Console.WriteLine("GrandFather Class Show() method is called.");
class Father: GrandFather
public int Age { get; set; }
public string City { get; set; }
public void Display(GrandFather grandFather)
Console.WriteLine("Father Class Display() : " + grandFather.GetType().ToString());
public virtual GrandFather Print(string type = "")
if (type.ToUpper() == "F")
else if (type.ToUpper() == "C")
return new GrandFather();
public override void Show()
Console.WriteLine("Father Class Show() method is called.");
public int Gender { get; set; }
public string DOB { get; set; }
public override void Show()
Console.WriteLine("Child Class Show() method is called.");
public override Father Print(string type = "")
if (type.ToUpper() == "F")
else if (type.ToUpper() == "C")
public static void Main()
Father father = new Father();
father.Display(new Child());
father.Display(new Father());
father.Display(new GrandFather());
(father.Print("F")).Show();
(father.Print("C")).Show();