class1:
public virtual void show()
class2:class1
public override void show ()
class3:class2
public override void show()
.................................................
how show() of class3 will overridable
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted May 3, 2014, 1:53 PM
The output is:
The reason for this state of affairs is that when you have a virtual or override method, the CLR always looks at the run time type of the variable, not its compile time type, in deciding which version of the method is to be called.
The run time type for this purpose is the actual type of object to which the variable refers.
So, in the case of these lines:
class3 d = new class4();
d.show();
whilst the compile type of 'd' is class3, its run time type is class4 and so it's class4's show method which gets called.