阿摩線上測驗 登入

試題詳解

試卷:104年 - SCJP 201-244#99410 | 科目:OJCP(SCJP)

試卷資訊

試卷名稱:104年 - SCJP 201-244#99410

年份:104年

科目:OJCP(SCJP)

206. Given: 
1. public class Drink implements Comparable{
2. public String name; 
3. public int compareTo(Object o){
 4. return 0;
 5. } 
6. }
 and:
 20. Drink one = new Drink(); 
21. Drink two = new Drink(); 
22. one.name = "Coffee"; 
23. two.name = "Tea"; 
24. TreeSet set = new TreeSet(); 
25. set.add(one); 
26. set.add(two);
 A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?
(A) Tea
(B) Coffee
(C) Coffee Tea
(D) Compilation fails.
(E) The code runs with no output.
正確答案:登入後查看