2
Answers

Pl. help me to understand this code (hiding)?

murali 0

murali 0

20y
2.1k
1
I saw this code in one of the notes. class A { public virtual void MyName() {Console.Writeline("My Name is A");} } class B:A { public override void MyName() {Console.Writeline("My Name is B");} } class C:B { public new virtual void MyName() {Console.Writeline("My Name is C");} } class D:C { public override void MyName() {Console.Writeline("My Name is D");} } C c = new D(); c.MyName(); //---------->prints "My name is D" A a = new D(); a.MyName(); //---------->prints "My name is B" ?????????? I thought a.MyName() should print "My name is D". Can any one explain why?. Any notes on hiding/Dynamic binding on the web/books? Thanks
Answers (2)
Next Recommended Forum