|
第十一題: |
|
Given the following: * d is
valid, non-null date object |
|
What outputs the current local's country name and the appropriate version of d's date? A. Locale loc = Locale.getLocal(); B. Locale loc = Locale.getDefault(); C. Locale loc = Locale.getLocal(); D. Locale
loc = Locale.getDefault(); |
|
答案:B |
|
執行結果:台灣 2011年9月4日 星期日 |
|
題目範圍:日期、地區的使用 |
|
解析: Locale 沒有getLocal() 方法,有getDefault()
方法 DateFormat 類別沒有setDateFormat()
方法,有format() 方法 請參閱:第四題 |
|
第十二題: |
|
Given the following: public class Hello implements Runnable { |
|
What is the result? A.
Compilation fails. |
|
答案:E |
|
執行結果:答案中 |
|
題目範圍:Thread 執行緒 |
|
解析: t.run(); 是使用一般函式呼叫,不管呼叫幾次都可以 |
|
第十三題: |
|
Given the
following: |
|
What is the result? A.
0,2,4,4,6,8,10,6, |
|
答案:AC |
|
執行結果:(下列其一) |
|
題目範圍:Thread 執行緒 |
|
解析: 這是同一個物件,以兩個執行緒來跑的情況 上面的執行結果只列出較有可能的不交替和只交替一次的結果 |
|
第十四題: |
|
Given the following: void waitForSignal() { Object obj = new Object(); synchronized (Thread.currentThread()) { obj.wait(); obj.notify(); } } |
|
Which statement is true? A. This code may throw an InterruptedException |
|
答案:A |
|
執行結果:無 |
|
題目範圍:Thread 執行緒 |
|
解析: 這題有兩個錯誤的地方,第一個錯誤是wait()方法要以try/catch包覆,或是擲出InterruptedException才行 第二個錯誤的地方是,synchronized 的目標與wait()方法的物件不相同,會有IllegalMonitorStateException ,不過InterruptedException 會先出現,所以這不是答案 最後正確的程式碼應該是這樣: Object obj = new Object(); synchronized (obj) { try { obj.wait(); } catch (InterruptedException e) { e.printStackTrace(); } obj.notify(); } } |
|
第十四題: |
|
Given the following: public class Test implements Runnable { |
|
What can be a result? A. Compilation fails |
|
答案:E |
|
執行結果:答案中 |
|
題目範圍:Thread 執行緒 |
|
解析: join()
方法的正確用法 |

第十二題的Test()哪來的?