বৃহস্পতিবার, ২৪ এপ্রিল, ২০১৪

Example of Virtual Function

//Visual Studio .NET, C#

//Virtual methods


using System;
class CLASS1
{
   public void F() { Console.WriteLine("One"); }
   public virtual void G() { Console.WriteLine("Two"); }
}
class CLASS2: CLASS1
{
   new public void F() { Console.WriteLine("Three"); }
   public override void G() { Console.WriteLine("Four"); }
}
class Test
{
   static void Main() {
      CLASS2 b = new CLASS2();
      CLASS1 a = b;
      a.F();
      b.F();
      a.G();
      b.G();
   }
}

OUT PUT:
One
Three
Four
Four

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন