Java Reference
In-Depth Information
<<interface>>
Complexity
+ getComplexity () : int
+ setComplexity (int) : void
MiniQuiz
+ main (args : String[]) : void
Question
+ getQuestion () : String
+ getAnswer () : String
+ answerCorrect (String) : boolean
+ toString() : String
FIGURE 7.3 A UML class diagram for the MiniQuiz program
As specified by the documentation for the interface, the integer that is returned
from the compareTo method should be negative if obj1 is less than obj2 , 0 if they
are equal, and positive if obj1 is greater than obj2 . It is up to the designer of each
class to decide what it means for one object of that class to be less than, equal to,
or greater than another.
In Chapter 5, we mentioned that the String class contains a compareTo
method that operates in this manner. Now we can clarify that the String class
has this method because it implements the Comparable interface. The String class
implementation of this method bases the comparison on the lexicographic order-
ing defined by the Unicode character set.
The Iterator Interface
The Iterator interface is another interface defined as part of the Java standard
class library. It is used by a class that represents a collection of objects, providing
a means to move through the collection one object at a time.
 
Search WWH ::




Custom Search