Implementing an Interface
Purpose:
- To create a class that accepts the responsibilities declared in one or more interfaces.
Mechanics:
<modifiers> class <class name> implements <interface list> {/* Instance variables declared and methods defined here */
}
Example:
public class myClass implements myInterface {/* Instance variables declared and methods defined here */
}
Usage:
- <modifiers> is an optional space-separated list of valid class modifiers.
- <class name> is any valid identifier unique to the current scope.
- <interface list> is a comma-separated list of
interfaces which the class should implement. It is expected that a
class which implements an interface will provide a definition for
every method declared in that interface. If it does not, then the
class must be declared
abstract. <class name> has direct access to all class constants defined in the interfaces it implements. - An interface in <interface list> may inherit from
one or more other interfaces. In this case, <class
name> must provide a definition for the methods declared in
the interface and all of its superinterfaces, or be declared
abstract. Likewise, <class name> has direct access to all class constants defined in the superinterfaces. - A class that implements interfaces can also inherit from a
superclass. The superclass must be extended before the interfaces
are implemented:
<modifiers> class <class name> extends <superclass name> implements <interface list> {/* Instance variables declared and methods defined */
}- public class myClass extends superClass implements myInterface
{
- /* Instance variables declared and methods defined */
}
email suggestions to: cs015tas@cs.brown.edu
