|
An interface is allowed to extend another interface. The syntax is
interface <interface_name> extends <parent_interface> { // Declarations and data }
The new interface consists of all the methods and data defined in the parent interface. For example, you might define the following:
package nature; interface SingingTalker extends Talker { public void sing(String song); }
This interface consists of the two methods defined in Talker (say() and repeat()), as well as sing(). A class that wants to implement this interface must use all three methods.
A class can extend only a single parent class, but an interface can extend multiple parent interfaces. For example, if InterA, InterB, and InterC are all interfaces, the following is legal:
interface ManyParents extends InterA, InterB, InterC { public int anotherMethod(double d, char ch); }
This interface consists of all the constants and methods of all three parents, plus the method defined explicitly in the source code.
|