Extending an Interface

Purpose:

To create an interface which inherits from one or more other interfaces.

Mechanics:

<modifiers> interface <interface name> extends <superinterface list> {
/* Class constants and abstract methods declared here */
}

Example:

public interface myInterface extends superInterface {
/* Class constants and abstract methods declared here */
}

Usage:

  • <modifiers> is an optional space-separated list of valid interface modifiers.
  • <interface name> is a valid identifier unique to the current scope.
  • <superinterface list> is a comma-separated list of interfaces from which this interface should inherit.
  • <interface name> will inherit all the method declarations and class constants in each of the interfaces listed in <superinterface list>. Thus the methods and class constants defined for <interface name> need be only those things needed to specialize the interface.
  • Any of the interfaces in <superinterface list> may also inherit methods and class constants; if so, <interface name> inherits everything that these interfaces inherit.
  • Variables may be declared of type <interface name> and defined as a class that implements the interface. Such references respond to all methods declared in the interface, or in any of its superinterfaces.

Restrictions:

Note that there is no analogue of the class Object for interfaces; that is, while every class inherits from class Object, there is no single interface from which all interfaces inherit.
Back to the Table of Contents
email suggestions to: cs015tas@cs.brown.edu