InterfaceDeclaration:A compile-time error occurs if the Identifier naming an interface appears as the name of any other class or interface in the same package. A compile-time error also occurs if the Identifier naming an interface appears as the name by which a class or interface is to be known via a single-type-import declaration in the compilation unit containing the interface declaration. In the example:
InterfaceModifiersoptinterface
Identifier
ExtendsInterfacesoptInterfaceBody
a compile-time error occurs because a
class Point { int x, y; }
interface Point { void move(int dx, int dy); }
class
and an interface
in the same package cannot have the same name.
InterfaceModifiers:A compile-time error occurs if the same modifier appears more than once in an interface declaration.
InterfaceModifier
InterfaceModifiers
InterfaceModifier InterfaceModifier: one of
public abstract
abstract
. This modifier is obsolete and should not
be used in new Java programs.
extends
clause is provided, then the interface being declared extends each
of the other named interfaces and therefore inherits the methods and constants of
each of the other named interfaces. These other named interfaces are the direct
superinterfaces of the interface being declared. Any class that implements
the
declared interface is also considered to implement all the interfaces that this interface extends
and that are accessible to the class.
ExtendsInterfaces:The following is repeated to make the presentation here clearer:
extends
InterfaceType
ExtendsInterfaces,
InterfaceType
InterfaceType:Each InterfaceType in the
TypeName
extends
clause of an interface declaration must name an accessible interface type; otherwise a compile-time error occurs.A compile-time error occurs if there is a circularity such that an interface directly or indirectly extends itself.
There is no analogue of the class Object
for interfaces; that is, while every class is an extension of class Object
, there is no single interface of which all interfaces are extensions.
The superinterface relationship is the transitive closure of the direct superinterface relationship. An interface K is a superinterface of interface I if either of the following is true:
InterfaceBody:The scope of the name of a member declared in an interface type is the entire body of the interface type declaration.
{
InterfaceMemberDeclarationsopt}
InterfaceMemberDeclarations:
InterfaceMemberDeclaration
InterfaceMemberDeclarationsInterfaceMemberDeclaration InterfaceMemberDeclaration:
ConstantDeclaration
AbstractMethodDeclaration
public
. They are accessible outside the
package where the interface is declared if the interface is also declared public
and the package containing the interface is accessible.