- using System;
- namespace Polymorphism
- {
- class A
- {
- public void Test() { Console.WriteLine("A::Test()"); }
- }
- class B : A
- {
- public new virtual void Test() { Console.WriteLine("B::Test()"); }
- }
- class C : B
- {
- public override void Test() { Console.WriteLine("C::Test()"); }
- }
- class Program
- {
- static void Main(string[] args)
- {
- A a = new A();
- B b = new B();
- C c = new C();
- a.Test(); // output --> "A::Test()"
- b.Test(); // output --> "B::Test()"
- c.Test(); // output --> "C::Test()"
- a = new B();
- a.Test(); // output --> "A::Test()"
- b = new C();
- b.Test(); // output --> "C::Test()"
- Console.ReadKey();
- }
- }
- }
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.

Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Aug 4, 2015, 11:21 AM EDT
amit shukla83 reputationPosted Aug 4, 2015, 6:51 PM EDT
Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Aug 5, 2015, 12:35 AM EDT
Syed ShanuRank #87 · 23.7K reputationPosted Aug 5, 2015, 12:58 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 5, 2015, 2:13 AM EDT
Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Aug 5, 2015, 7:48 AM EDT
Quote:
In class C you are inheriting the class B. But in class C you are over riding the Bclass method so the out but here display is-