Ash*_*ohn 11 c# methods virtual overloading
考虑一下代码
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);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我创建Derived类的实例并使用int类型的参数调用Add,为什么它使用float参数调用Add方法
Derived obj =new Derived()
obj.Add(3,5)
// why this is calling
Add(float a,float b)
Run Code Online (Sandbox Code Playgroud)
为什么不调用更具体的方法?
| 归档时间: |
|
| 查看次数: |
1464 次 |
| 最近记录: |