Course Content‎ > ‎Session 10‎ > ‎

Interface Declaration & Body

Interface Declaration
 
A minimum interface declaration contains the Java keyword interface and the name of the interface. An interface declaration can have two other components:
 
    - the public access specifier and
     
    - a list of "superinterfaces".

An interface can extend other interfaces.  A class can only extend one other class, an interface can extend any number of interfaces. That’s why it is thought that interfaces provide a way of multiple inheritance in Java. The public access specifier indicates that the interface can be used by any class in any package. If omitted, the interface will only be accessible to classes that are defined in the same package. The extends clause is similar to the extends clause in a class declaration. An interface cannot extend classes. The list of superinterfaces is a comma-separated list of all of the interfaces extended by the new interface. An interface inherits all constants and methods from its superinterface unless:

    1. the interface hides a constant with another of the same name, or
    
    2. redeclares a method with a new method declaration.

Interface Body

The body of the interface contains method declarations. The method declaration does not have a method body. All methods declared in an interface are public and abstract. The body of the interface may also define constants. Constant values defined in an interface are public, static, and final.

Comments