I have created two objects of Manager class in Main() as below:
Manager mgr = new Manager();
Employee emp= new Manager();
What I theoretically understand is that 1st object creation [mgr] is compile time binding whereas 2nd object creation [emp] is run time binding. But I want to understand it practically what actually happens that decides that function call will be binded to Function name at compile time [in my case, mgr] or run time [in my case, emp].
What I understand here is that, in both these situations objects are to be created at run time only. If I say new Manager() then it has to create object of Manager only. So, Please suggest what actually happens at run time that is not the case with compile time.
namespace EarlyNLateBinding
{
class Employee
{
public virtual double CalculateSalary(double basic, double hra, double da)
{
return basic + hra + da;
}
}
class Manager:Employee
{
double allowances = 4000;
public override double CalculateSalary(double basic, double hra, double da)
{
return basic + hra + da+allowances;
}
}
class Program
{
static void Main(string[] args)
{
Employee emp= new Manager();
double empsalary = emp.CalculateSalary(35000, 27000, 5000);
Console.WriteLine(empsalary.ToString());
Manager mgr = new Manager();
double mgrsalary = mgr.CalculateSalary(35000, 27000, 5000);
Console.WriteLine(mgrsalary.ToString());
Console.Read();
}
}
}