Loading
notes intro/old submit AP Problems the dump links
 

Quiz 15b - Comparable

 

 

id:

1. If your class Player implemented the interface Comparable, what is the method you would need to write:

public void compareTo (Object o)

public int compareTo (Object o)

public void compareTo (Player o)

public int compareTo (Player o)

 

2. True or false: Like the .equals method, all classes have a compareTo method built in, you just can overwrite it true false

3. True or false: If you try to cast an object of the wrong type, it would result in a runtime error. true false

4. If you had a Player class that implemented Comparable, which of these might be the body of the compareTo method:

return this.getScore()-o.getScore();

return this.getScore()-(Player)o.getScore();

return this.getScore()-((Player)o).getScore();

return this-o;