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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -