呵呵呵~忙錄、忙忙忙,但我又有新的問題啦!這次的分別是commarTo()、equals(), hashCode(),及Class Cast的問題嘍!大笑
而且值得慶幸的是:我不會的題目有比較少唷XD所以這次才一次有那麼多不同類型的題目啊!吐舌頭

第23題:
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.
F. An exception is thrown at runtime.

為何答案只有Coffee呢?為何不是Coffee Tea哩?(十萬個為什麼@@)

 

第191題:
Given:
11. public class Person {
12.     private String name, comment;
13.     private int age;
14.     public Person(String n, int a, String c) {
15.         name = n; age = a; comment = c;
16.     }
17.     public boolean equals(Object o) {
18.         if (! (o instanceof Person)) return false;
19,         Person p = (Person)o;
20.         return age == p.age && name.equals(p.name);
21.     }
22. }

What is the appropriate definition of the hashCode method in class Person?

A. return super.hashCode();
B. return name.hashCode() + age * 7;
C. return name.hashCode() + comment.hashCode() / 2;
D. return name.hashCode() + comment.hashCode() / 2 - age * 3;

為何答案是B而不是A呢?我搞不太懂說Orz.

 

第9題:
Given:
1. class Super {
2.     private int a;
3.     protected Super(int a) { this.a = a; }
4. }
...
11. class Sub extends Super {
12.     public Sub(int a) { super(a); }
13.     public Sub() { this.a = 5; }
14. }

Which two, independently, will allow Sub to compile? (Choose two.)

A. Change line 2 to:
     public int a;
B. Change line 2 to:
     protected int a;
C. Change line 13 to:
     public Sub() { this(5); }
D. Change line 13 to:
     public Sub() { super(5); }
E. Change line 13 to:
     public Sub() { super(a); }

Why?why?CD對嗎?WHY???

 

第109題:
 What two must the programmer do to correct the compilation errors? (Choose two.)

 

A. insert a call to this() in the Car constructor
B. insert a call to this() in the MeGo constructor
C. insert a call to super() in the MeGo constructor
D. insert a call to super(vin) in the MeGo constructor
E. change the wheelCount variable in Car to protected
F. change line 3 in the MeGo class to super.wheelCount = 3;

這題我陣亡了Orz

 

第126題:
What is the result?

A. 4321
B. 0000
C. An exception is thrown at runtime
D. Compilation fails because of an error in line 18.

為何答案是D不是A哩?

 

第324題:

Given:
11. class Cup { }
12. class PoisonCup extends Cup {
}

...
21. public void takeCup(Cup c) {
22.     if (c instanceof PoisonCup) {
23.         System.out.println("Inconceivable!");
24.     } else if (c instanceof Cup) {
25.         System.out.println("Dizzying intellect!");
26.     } else {
27.         System.exit(0);
28.     }
29. }

And the execution of the statements:
Cup cup = new PoisonCup();
takeCup(cup);
What is the output?

A. Inconceivable!
B. Dizzying intellect!
C. The code runs with no output.
D. An exception is thrown at runtime.
E. Compilation fails because of an error in line 22.

請救救我吧Orz...

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 如雲 的頭像
    如雲

    如雲似水

    如雲 發表在 痞客邦 留言(9) 人氣()