Extending Interfaces


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.




Ground-Up Java
Ground-Up Java
ISBN: 0782141900
EAN: 2147483647
Year: 2005
Pages: 157
Authors: Philip Heller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net