AP计算机教程9-10:继承和interface
Java中的interface是一种特殊的abstract class
,仅能包含public abstract
method(虽然这两个关键词是被省略的)以及public
的常数。Java中的List
是一个很典型的interface。可以用interface
关键字来声明interface,某个interface也可以继承另一个interface。
public interface Checker { boolean check (Object obj); }
上述代码声明了一个名叫Checker
的interface,包含有名为check
的public abstract
method,返回true
或false
的布尔值。实现这个interface的class必须提供check
method的具体实现。
Java中另一个interface的例子是Iterator
。我们用它来循环遍历集合class。
0:00
Which of the following is true about interfaces?
I. Interfaces can only contain abstract methods or class constants.
II. Interfaces can be extended.
III. Interfaces can be instantiated (you can create an object of the interface type).
interface可以被另一个interface继承,但是不能被实例化。
3
0 条评论