Java Reference
In-Depth Information
int TERSE = 1;
int NORMAL = 2;
int VERBOSE = 3;
void setVerbosity(int level);
int getVerbosity();
}
SILENT , TERSE , NORMAL , and VERBOSE can be passed to the setVerbosity
method, giving names to constant values that represent specific mean-
ings. In this particular case, the verbosity levels could be more effect-
ively represented as the constants of an enumeration type nested within
the Verbose interface. Enumeration types are discussed in Chapter 6 .
If you need shared, modifiable data in your interface you can achieve
this by using a named constant that refers to an object that holds the
data. A nested class is good for defining that object, so we defer an ex-
ample until Chapter 5 .
4.2.2. Interface Methods
The methods declared in an interface are implicitly abstract because no
implementation is, or can be, given for them. For this reason the meth-
od body is simply a semicolon after the method header. By convention,
the abstract modifier on the method declaration is omitted.
No other method modifiers are permitted on an interface method declar-
ation, except for annotationssee Chapter 15 . They are implicitly public
and so can have no other access modifier. They cannot have modifiers
that define implementation characteristicssuch as native , synchronized ,
or strictfp because an interface does not dictate implementation, and
they cannot be final because they haven't been implemented yet. Of
course, the implementation of these methods within a specific class can
have any of these modifiers. Interface methods can never be static be-
cause static methods can't be abstract .
 
Search WWH ::




Custom Search