//inteface i11
public interface i11
{
void m11();
}
//interface i22
public interface i22
{
void m11();
}
//class ab implements interfaces i11 and i22
public class ab : i11, i22
{
public void m11()
{
Console.WriteLine("class");
}
}
现在在 Main() 方法中我们创建了一个类 ab 的对象 将调用哪个接口(interface)方法请解释所有。
最佳答案
只有一个方法实现,所以很明显它会被调用,而不管引用的类型如何。即:
i11 o = new ab();
o.m11();
和
i22 o = new ab();
o.m11();
实际上是一样的。
ab.m11
满足两个接口(interface)中方法的签名。另外,您没有使用 explicit interface implementation ,所以这不是一个因素。
关于c# - 实现定义相同方法的两个接口(interface)的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4638218/