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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted May 3, 2014, 9:53 AM EDT
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.