- 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 ZeeshanPosted Aug 5, 2015, 11:48 AM
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-
Upendra Pratap ShahiPosted Aug 5, 2015, 6:13 AM
Syed ShanuPosted Aug 5, 2015, 4:58 AM
Afzaal Ahmad ZeeshanPosted Aug 5, 2015, 4:35 AM
amit shuklaPosted Aug 4, 2015, 10:51 PM
Afzaal Ahmad ZeeshanPosted Aug 4, 2015, 3:21 PM