Sunday, 4 November 2012

Program to demonstrate the use of virtual and override keyword


using System;
class GrandParent
{
 public virtual void Display()
 {
  Console.WriteLine("GrandParent Class Method");
 }
}
class Parent : GrandParent
{
 public override void Display()
 {
  Console.WriteLine("Parent Class Method");
 }
}
class Child : Parent
{
  public override void Display()
  {
   Console.WriteLine("Child Class Method");
  }
}
class HideTest
{
 static void Main()
 {
  Child d=new Child();
  d.Display();
  Console.ReadKey();
 }
}

Output:-

No comments:

Post a Comment