Oracle
1Z0-851 · Question #93
Given: public class Drink implements Comparable { public String name; public int compareTo(Object o) { return 0; } } and: Drink one = new Drink(); Drink two = new Drink(); one.name= "Coffee"…
The correct answer is B. Coffee. See the full explanation below for the reasoning.
Question
Given: public class Drink implements Comparable { public String name; public int compareTo(Object o) { return 0; } } and: Drink one = new Drink(); Drink two = new Drink(); one.name= "Coffee"; two.name= "Tea"; TreeSet set = new TreeSet(); set.add(one); set.add(two); A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?
Options
- ATea
- BCoffee
- CCoffee Tea
- DCompilation fails.
- EThe code runs with no output.
- FAn exception is thrown at runtime.
How the community answered
(34 responses)- A3% (1)
- B74% (25)
- C3% (1)
- D15% (5)
- F6% (2)
Community Discussion
No community discussion yet for this question.