Oracle
1Z0-851 · Question #5
Given: public class Score implements Comparable<Score> { private int wins, losses; public Score(int w, int l) { wins = w; losses = l; } public int getWins() { return wins; } public int getLosses() {…
The correct answer is B. public int compareTo(Score other){/*more code here*/}. See the full explanation below for the reasoning.
Question
Given: public class Score implements Comparable<Score> { private int wins, losses; public Score(int w, int l) { wins = w; losses = l; } 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?
Options
- Apublic int compareTo(Object o){/more code here/}
- Bpublic int compareTo(Score other){/more code here/}
- Cpublic int compare(Score s1,Score s2){/more code here/}
- Dpublic int compare(Object o1,Object o2){/more code here/}
How the community answered
(40 responses)- A8% (3)
- B70% (28)
- C5% (2)
- D18% (7)
Community Discussion
No community discussion yet for this question.