I have the following code sample :
public class Base
{
public virtual void MyMethod(int param)
{
Console.WriteLine("Base:MyMethod - Int {0}", param);
}
}
public class Derived1 : Base
{
public override void MyMethod(int param)
{
Console.WriteLine("Derived1:MyMethod - Int {0}", param);
}
public void MyMethod(double param)
{
Console.WriteLine("Derived1:MyMethod - Double {0}", param);
}
}
class Program
{
static void Main(string[] args)
{
Base objB = new Base();
objB.MyMethod(5);
Base objBD = new Derived1();
objBD.MyMethod(5);
Derived1 objD = new Derived1();
objD.MyMethod(5);
Console.ReadLine();
}
}
The output of the above code is as follows:
Base:MyMethod - Int 5
Derived1:MyMethod - Int 5
Derived1:MyMethod - Double 5
For the third invocation of 'MyMethod' using 'objD' why is the 'DOUBLE' overload being used when I am actually passing it an INT.
The second invocation using 'objBD' seems to behave correctly. Please suggest.