created: July 06, 2006, revised: 11/01/2012


Quiz on Comparable

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.


1. An interface, in general, is a list of what things?

A.    methods and variables

B.    classes and constants

C.    methods

D.    methods and constants

Correct Answer:


2. Say that you are writing a class Book and wish it to implement the Comparable<Book> interface. What method must Book contain?

A.    int compareTo( Book other )

B.    int compareTo( Object other )

C.    Book compareTo( Object other )

D.    boolean compareTo( T other )

Correct Answer:


3. What is the value of "zebra".compareTo("emu")

A.    a negative integer

B.    0

C.    a positive integer

D.    unpredictable

Correct Answer:


4. What is the value of (new Integer(5)).compareTo( new Integer(8) )

A.    a negative integer

B.    0

C.    a positive integer

D.    unpredictable

Correct Answer:


5. If the objects of a class are arranged into their natural order, then if object L is left of object R what is true?

A.    L.compareTo(R) is positive

B.    L.compareTo(R) is negative

C.    L.compareTo(R) is zero

D.    R.compareTo(L) is negative

Correct Answer:


6. If X.compareTo(Y) is positive, then which of the following is true?

A.    Y.compareTo(X) is positive

B.    Y.compareTo(X) is negative

C.    Y.compareTo(X) is zero

D.    Y.compareTo(X) is unknown

Correct Answer:


7. If X.equals(Y) is true, then which of the following is true for most classes that implement Comparable?

A.    X.compareTo(Y) is negative

B.    X.compareTo(Y) is zero

C.    X.compareTo(Y) is positive

D.    Nothing can be said.

Correct Answer:


8. What is "ZURICH".compareTo("cairo")

A.    a negative integer

B.    zero

C.    a positive integer

D.    unknown

Correct Answer:


9. What is "pit viper".compareTo("pit")

A.    a negative integer

B.    zero

C.    a positive integer

D.    unknown

Correct Answer:


10. What algorithm quickly searches an ordered array?

A.    binary search

B.    linear search

C.    random search

D.    ordered search

Correct Answer:


The number you got right:       Percent Correct:       Letter Grade:   


Click here If you have returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the SHIFT KEY while clicking to clear the old answers.