fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. class A
  6. {
  7. public void foo()
  8. {
  9. Console.WriteLine("A::foo()");
  10. }
  11. public virtual void bar()
  12. {
  13. Console.WriteLine("A::bar()");
  14. }
  15. }
  16.  
  17. class B : A
  18. {
  19. public /*new*/ void foo()
  20. {
  21. Console.WriteLine("B::foo()");
  22. }
  23. public override void bar()
  24. {
  25. Console.WriteLine("B::bar()");
  26. }
  27. }
  28.  
  29. public static void Main()
  30. {
  31. B b = new B();
  32. A a = b;
  33. a.foo(); // Prints A::foo
  34. b.foo(); // Prints B::foo
  35. a.bar(); // Prints B::bar
  36. b.bar(); // Prints B::bar
  37. }
  38. }
Success #stdin #stdout 0s 131648KB
stdin
Standard input is empty
stdout
A::foo()
B::foo()
B::bar()
B::bar()