J2EEOnline
GofPatterns OOPortal
prev next prev next
  Course navigation
 
Lesson 6
Objective
Interface declarations
Describe the declaration and use of interfaces.
    Interfaces
Interfaces are used to define collections of methods that are implemented by classes. However, they may also define constants, inner classes, and inner interfaces. Their syntax is as follows:
modifiers interface InterfaceName extends  {
 // Interface body
}
Valid modifiers are public and abstract. A public interface may be accessed outside of its package. All interfaces are implicitly abstract. The extends clause consists of extends followed by a comma-separated list of interfaces. If interface X extends interfaces Y and Z, then X inherits all of the constants and methods of Y and Z.
The interface body consists of constant declarations, abstract method declarations, inner classes, and inner interfaces. Inner classes and interfaces are covered later in this module. A constant definition is the declaration and initialization of a variable that is public, static, and final. The variables modifiers are optional.
An abstract method declaration is specified as follows:
modifiers returnType methodName(arguments) throwsClause;
Note the semicolon replaces the method body. Methods are implicitly abstract and public. They may not be declared static, native, final, or synchronized.
  Course navigation