Suppose objects a and b are from a user-defined class that implements the Comparable interface.What must be true about the return value of a.compareTo(b) for the compareTo method that this class implements?
A) It must return 1 if a comes before b, 0 if they are the same, and -1 if a comes after b.
B) It must return -1 if a comes before b, 0 if they are the same, and 1 if a comes after b.
C) It must return a negative value if a comes before b, 0 if they are the same, and a positive value if a comes after b.
D) It must return a positive value if a comes before b, 0 if they are the same, and a negative value if a comes after b.
Correct Answer:
Verified
Q89: The binarySearch method of the Collections class
Q90: Suppose you wish to implement the Comparable
Q91: If a call to the Arrays static
Q92: Suppose you wish to sort an array
Q93: The Comparable interface consists of a single
Q95: Given the following code snippet for searching
Q96: Suppose objects a and b are from
Q97: Given the following code snippet for searching
Q98: Which of the following arrays can be
Q99: Complete the code shown to define the
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents