Syntax
>>-+--------+-interface-Identifier-+---------------------------+-> '-public-' '-extends-InterfaceTypeList-' v---------------------' v---------------------------' >-{-+---------------------+-+---------------------------+-}->< '-ConstantDeclaration-' '-AbstractMethodDeclaration-'
Description
An interface declaration introduces a new reference type whose
members are constants and abstract methods. The Identifier specifies the name
of the interface and has as its scope the entire package in which it is declared.
An interface may be declared to be a direct extension of one or more other interfaces, meaning that it implicitly specifies all the abstract methods and constants of the interfaces that it extends, except for any constants that it may hide. A class may be declared to directly implement one or more interfaces, meaning that any instance of the class implements all the abstract methods specified by the interface or interfaces. A class necessarily implements all the interfaces that its direct superclasses and direct superinterfaces do. This (multiple) interface inheritance allows objects to support (multiple) common behaviors without sharing any implementation.
If the Identifier naming an interface appears as the name of any other class or interface in the same package, a compilation error 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, a compilation error occurs.
If an 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.
Example
The following is an example of a simple interface declaration:
/* * This interface defines the methods that a * list pane item should implement. */ public interface ListPaneItem { ... }
In the following example a compilation error occurs because a class and an interface in the same package cannot have the same name:
public class Point { int x, y; } interface Point { void move(int dx, int dy); }
Syntax diagrams
abstract keyword
class keyword
final keyword
public keyword
Source: The Java Language Specification. Copyright (C) 1996 Sun Microsystems, Inc.