amit shukla

amit shukla

  • NA
  • 78
  • 66.9k

give the region

Aug 4 2015 2:46 PM
  1. using System;
  2. namespace Polymorphism
  3. {
  4. class A
  5. {
  6. public void Test() { Console.WriteLine("A::Test()"); }
  7. }
  8. class B : A
  9. {
  10. public new virtual void Test() { Console.WriteLine("B::Test()"); }
  11. }
  12. class C : B
  13. {
  14. public override void Test() { Console.WriteLine("C::Test()"); }
  15. }
  16. class Program
  17. {
  18. static void Main(string[] args)
  19. {
  20. A a = new A();
  21. B b = new B();
  22. C c = new C();
  23. a.Test(); // output --> "A::Test()"
  24. b.Test(); // output --> "B::Test()"
  25. c.Test(); // output --> "C::Test()"
  26. a = new B();
  27. a.Test(); // output --> "A::Test()"
  28. b = new C();
  29. b.Test(); // output --> "C::Test()"
  30. Console.ReadKey();
  31. }
  32. }
  33. }
please give the logical answer.
why a.test() call  A class function and why b.test() call C class test() function .
please share only technical region. 
 
 
 

Answers (6)