c# inheritance override question -
fixed issues code. ok, think need clarify question.
new a.example(); outputs "a"
what should inside example method output "???"? possible?
public class letter { public virtual void asastring() { console.writeline("???"); } public void example() { this.asastring(); } } public class : letter { public override void asastring() { console.writeline("a"); } public void example2() { base.asastring(); } } new a().example2(); new a().example();
that's easy:
public void example() { console.writeline("???"); }
from answer should realise asked wasn't thought asked for...
if mean want call virtual method if wasn't virtual, not possible. if cast reference base class, still uses actual type of object determine method call.
Comments
Post a Comment