两个接口具有相同的方法 [英] Two interfaces have same method
本文介绍了两个接口具有相同的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Interface A
{
int Add(int a,int b);
}
Interface B
{
int Add(int a,int b);
}
Class D : A, B
{
int Add(int a,int b)
{
return a+b;
}
}
代码工作正常,没有产生任何错误.D类正在使用哪个接口的方法?
Code works fine and didn't produce any error. Class D is using which interface's method?
推荐答案
都没有,因为这两个接口都没有方法,仅是方法签名.您在D中的方法实现了两个接口提供的签名,因此可以正常工作.
Neither, since neither interface HAS a method, merely a method signature. Your method in D implements the signature provided by both interfaces, so it works.
请记住,接口仅指定实现中必须存在的方法的签名.
Remember, an interface merely specifies the signatures of methods that must exist in an implementation.
这篇关于两个接口具有相同的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文