An interface declaration consists of modifiers, the keyword interface
, the interface name, a comma-separated list of parent interfaces (if any), and the interface body. For example:
public interface GroupedInterface extends Interface1, Interface2, Interface3 {
// constant declarations
// base of natural logarithms
double E = 2.718282;
// method signatures
void doSomething (int i, double x);
int doSomethingElse(String s);
}
An interface can extend other interfaces, just as a class subclass or extend another class. However, whereas a class can extend only one other class, an interface can extend any number of interfaces. The interface declaration includes a comma-separated list of all the interfaces that it extends.
就像子类继承父类一样,一个接口可以继承任意其他的接口。但是,一个类只能继承一个超类,一个接口却可以继承任意数量的接口。接口声明包括用逗号隔开的一系列被继承的接口。