c# - base class extended object implamentation -


bit of noobie question hey ho.

example:

baseclass bc = new extendedclass(); //assume extendedclass inherits baseclass ((baseclass)bc).extendedmethod(); bc.extendedmethod(); ((extendedclass)bc).extendedmethod(); //overridden in extendedclass  extendedclass ec = new extendedclass(); ((baseclass)ec).extendedmethod(); ec.extendedmethod(); ((extendedclass)ec).extendedmethod(); //overridden in extendedclass  

?

what implementations bc.extendedmethod(); , ec.extendedmethod(); call @ runtime? different? assume casted calls call specific implementation within class.

edit: added relevant tag.

public class base {     public void extends()     {         console.writeline("base class");     } }  public class extend : base {     public new void extends()     {         console.writeline("extend class");     } }   public class program {     public static void main()     {          base b = new base();         b.extends();          extend e = new extend();         e.extends();          base = new extend();         be.extends();          console.read();     }  } 

results in following output:

base class extend class base class 

note can use new keyword in extend class hide base extends function.

public new void extends()  {  } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -