Neo*_*Neo 3 c# oop interface-implementation
//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");
}
}
Run Code Online (Sandbox Code Playgroud)
现在在Main()方法中我们创建了一个类ab的对象,接口方法将被调用,请解释所有.
只有一种方法实现,所以无论引用的类型如何,都会被调用.IE:
i11 o = new ab();
o.m11();
Run Code Online (Sandbox Code Playgroud)
和
i22 o = new ab();
o.m11();
Run Code Online (Sandbox Code Playgroud)
实际上是一样的.
ab.m11满足两个接口中方法的签名.此外,您没有使用显式接口实现,因此这不是一个因素.