C# Early and Late Binding concept -


as known binding concept of declaring object of specific data type, , cant hold other type of object. while late binding concept of declaring object of generic type , can hold instance of other type. consider example:

public abstract class animal   {   public virtual string name { { return "animal"; } }  }   public class dog : animal  {    public override string name { { return "dog"; } }  }   public class cat : animal  {    public override string name { { return "cat"; } }  }   public class test   {    static void main()    {       animal animal = new dog();        animal animaltwo = new cat();         console.writeline(animal.name);        console.writeline(animaltwo.name);     }  }  

my question when compilor recognize function call of object, either @ compile time or run time? sorry if unclear. mean ask concept of virtual on riding , virtual methods involve late binding or not? .. if not how possible.

runtime.

a virtual function means dispatch routed @ runtime function on live object reference. in c++ done via table of pointers called vtable. i'm not sure how c# it, assume implementation dependant, result same.

at compile time compiler bind function call function on base class. base class function virtual, @ runtime .net @ actual object type , see if overrides function. if derived type called.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -