接口实现
我被问到以下问题:
a) 接口 IntSet 有一个名为 isElem 的方法。该方法需要一个 int 类型的单个参数并返回布尔结果。 完整定义接口 IntSet。
到目前为止我的答案已经有了。任何帮助将不胜感激。谢谢
public interface Intset {
public abstract boolean isElem (int a)
}
I have been asked the following question:
a) The interface IntSet has a single method called isElem. The method takes a
single parameter of type int and returns a boolean result.
Define the interface IntSet in full.
So far for my answer I have. Any help would be appreciated. Thanks
public interface Intset {
public abstract boolean isElem (int a)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
正确的解决方案是:
你忘记了 ;在方法定义的末尾,并且类名中有一个小拼写错误。
请注意,关键字
public
和abstract
是可选的,在这种情况下不鼓励使用。The correct solution is:
You forgot the ; at the end of the method definition, and you had a small typo in the class name.
Note that the keywords
public
andabstract
are optional and discouraged in this case.除了结尾的分号之外,您已经完成了问题。
apart from the trailing semi-colon, you have completed the question.
你忘了写
;
并且接口方法默认是公共和抽象的,所以你可以写
或
you forgot to write
;
and in interface methods are by default pulbic and abstract soyou can write
or
由于接口中的每个方法默认都是公共和抽象的,因此
我会从代码中删除
公共抽象
。你很少看到这一点,因为它是多余的。来自 Java 语言规范 第 9.4 节:
语法:
还演示了接口中声明的所有方法都是抽象的。
Since every method in an interface is by default public and abstract
I would drop the
public abstract
from the code. You rarely see this, since it is redundant.From the Java Language Specification, Section 9.4:
and the grammar:
also demonstrates all methods declared in an interface are abstract.