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

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

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