nerdexam
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)
  • A
    3% (1)
  • B
    74% (25)
  • C
    3% (1)
  • D
    15% (5)
  • F
    6% (2)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice