If a class is using an interface, it must:
(1) inherit the properties of the interface
(2) contain the same methods as the interface
(3) create an interface object
(4) all of the above
正确答案是 (4)以上所有。
注意:这来自here而且我不知道这个问题的作者到底是谁。
我同意 (1)st 和 (2)nd,但我会争论 (3)rd 的措辞。
我猜它可以被双重解释;
创建一个接口(interface)对象可能只是一个继承接口(interface)的类的实例
或
接口(interface)类型的引用变量
正确的解读方式是什么?
以下是否有意义?
If a class is using an interface, it must:
(1) inherit the properties of the interface
(2) provide implementation for all methods that the interface exposes
(3) ???
(4) all of the above
最佳答案
(2) provide implementation for all methods that the interface exposes
没有。抽象类可以在不提供实现的情况下实现接口(interface)(它们仍然必须声明接口(interface)中定义的方法,但它们不必提供主体)。
不过我也不知道如何解释数字 3。通过您提供的链接查看时,这只是问题措辞不当的问题。我仍在尝试弄清楚这意味着什么:
- 代码 public class B : A { } 的输出是什么
- 错误
- 它定义了一个只继承A的公共(public)方法的类。
- 定义了一个继承A所有方法但私有(private)成员不可访问的类。
- b和c
关于c# - 如果一个类正在使用一个接口(interface),它必须,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20218708/