Consider the code
public class Base
{
public virtual int Add(int a,int b)
{
return a+b;
}
}
public class Derived:Base
{
public override int Add(int a,int b)
{
return a+b;
}
public int Add(float a,float b)
{
return (Int32)(a + b);
}
}
If I create an instance of Derived class and call Add with parameters of type int why it is calling the Add method with float parameters
Derived obj =new Derived()
obj.Add(3,5)
// why this is calling
Add(float a,float b)
Why it is not calling the more specific method?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…