单项选择题

public class Score implements Comparable { 
private int wins, losses; 
public Score(int w, int 1) { wins = w; losses = 1; } 
public int getWins() { return wins; } 
public int getLosses() { return losses; } 
public String toString() { 
return “<“ + wins + “,“ + losses + “>”;
} 
// insert code here 
} 
Which method will complete this class?() 

A. public int compareTo(Object o) {/*mode code here*/}
B. public int compareTo(Score other) {/*more code here*/}
C. public int compare(Score s1,Score s2){/*more code here*/}
D. public int compare(Object o1,Object o2){/*more code here*/}


您可能感兴趣的试卷

你可能感兴趣的试题

1.单项选择题

1. import java.util.*; 
2. public class TestSet { 
3. enum Example { ONE, TWO, THREE } 
4. public static void main(String[] args) { 
5. Collection coll = new ArrayList(); 
6. coll.add(Example.THREE); 
7. coll.add(Example.THREE); 
8. coll.add(Example.THREE); 
9. coll.add(Example.TWO); 
10. coll.add(Example.TWO); 
11. coll.add(Example.ONE); 
12. Set set = new HashSet(coll); 
13. } 
14. } 
Which statement is true about the set variable on line 12?() 

A. The set variable contains all six elements from the coll collection, and the order is guaranteed to be preserved.
B. The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved.
C. The set variable contains all six elements from the coil collection, but the order is NOT guaranteed to be preserved.
D. The set variable contains only three elements from the coil collection, but the order is NOT guaranteed to be preserved.

6.多项选择题Which two are true about has-a and is-a relationships?()

A. Inheritance represents an is-a relationship.
B. Inheritance represents a has-a relationship.
C. Interfaces must be used when creating a has-a relationship.
D. Instance variables can be used when creating a has-a relationship.

7.多项选择题Which four are true?()

A. Has-a relationships should never be encapsulated.
B. Has-a relationships should be implemented using inheritance.
C. Has-a relationships can be implemented using instance variables.
D. Is-a relationships can be implemented using the extends keyword.
E. Is-a relationships can be implemented using the implements keyword.
F. An array or a collection can be used to implement a one-to-many has-a relationship.
G. The relationship between Movie and Actress is an example of an is-a relationship.

8.多项选择题

public class Team extends java.util.LinkedList { 
public void addPlayer(Player p) { 
add(p); 
} 
public void compete(Team opponent) { /* more code here */ } 
} 
class Player { /* more code here */ } 
Which two are true?()

A. This code will compile.
B. This code demonstrates proper design of an is-a relationship.
C. This code demonstrates proper design of a has-a relationship.
D. A Java programmer using the Team class could remove Player objects from a Team object.