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


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 )


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

A.    a negative integer

B.    0

C.    a positive integer

D.    unpredictable


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


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


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


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.


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

A.    a negative integer

B.    zero

C.    a positive integer

D.    unknown


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

A.    a negative integer

B.    zero

C.    a positive integer

D.    unknown


10. What algorithm quickly searches an ordered array?

A.    binary search

B.    linear search

C.    random search

D.    ordered search


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.