As its known that early binding is the concept of declaring the object of specific data type, and it cant hold any other type of object. While late binding is the concept of declaring object of generic type and that can hold the instance of any other type. Consider the example:
public abstract class Animal
{
public virtual string Name { get { return "Animal"; } }
}
public class Dog : Animal
{
public override string Name { get { return "Dog"; } }
}
public class Cat : Animal
{
public override string Name { get { 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 is THAT when will the compilor recognize the function call of object, either it will be at compile time or run time? I am sorry if i am unclear. But i mean to ask that does the concept of Virtual over riding and virtual methods involve late binding or not? .. if not then how is this possible.