fork download
  1. using System;
  2.  
  3. class A
  4. {
  5. public virtual void Foo() { Console.WriteLine("A"); }
  6. }
  7.  
  8. class B : A
  9. {
  10. public new virtual void Foo() { Console.WriteLine("B"); }
  11. }
  12.  
  13. class C : B
  14. {
  15. public override void Foo() { Console.WriteLine("C"); }
  16. }
  17.  
  18.  
  19. public class Test
  20. {
  21. public static void Main()
  22. {
  23. ((A)(new A())).Foo();
  24. ((A)(new B())).Foo();
  25. ((A)(new C())).Foo();
  26.  
  27. ((B)(new B())).Foo();
  28. ((B)(new C())).Foo();
  29.  
  30. ((C)(new C())).Foo();
  31.  
  32. }
  33. }
Success #stdin #stdout 0.03s 23880KB
stdin
Standard input is empty
stdout
A
A
A
B
C
C