Flyinsky

志在四方,浪迹天涯

导航

Virtual

We code every day but maybe we don't know the base theory clearly.The below example is about virtual method in C#,
what is the correct output?
Be frank with you,I don't comprehend the "Virtual methods" plenty,may be you will let me to look out
it in MSDN,but can you give the correct output and the pellucid explannation here? Thanks.

using System;
class A
{
   
public virtual void F() { Console.WriteLine("A.F"); }
}

class B: A
{
   
public override void F() { Console.WriteLine("B.F"); }
}

class C: B
{
   
new public virtual void F() { Console.WriteLine("C.F"); }
}

class D: C
{
   
public override void F() { Console.WriteLine("D.F"); }
}

class Test
{
   
static void Main() {
      D d 
= new D();
      A a 
= d;
      B b 
= d;
      C c 
= d;
      a.F();
      b.F();
      c.F();
      d.F();
   }

}

posted on 2004-08-18 16:04  flyinsky  阅读(559)  评论(3编辑  收藏  举报