第121題: |
Given: 11. public class Test{ |
What is the result? A. harrier B. shepherd C. retriever D. Compilation fails E. retriever harrier F. An exception is thrown at runtime, |
答案:D |
題目範圍:基本觀念,switch |
解析: 這題藏了三個錯誤,分別是: Enum那行最後的逗號應該被刪掉 System.out.print("retriever "), 的逗號 還有case default: 應該改為default: |
第122題: |
Given: 11. public void genNumbers(){ |
Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection? A. Line 16 B. Line 17 C. Line 18 D. Line 19 E. The object is NOT a candidate for garbage collection. |
答案:D |
題目範圍:物件與指標觀念,回收處理 |
解析: 如果沒有numbers.add(intObj);這個指令,intObj 會在17行每次回圈跑完時被回收掉 不過因為numbers.add(intObj);的關係,每次回圈產生的intObj 指標都會被放在numbers 中,直到19行才會被回收 |
第123題: |
Given: 11. public static void parse(String str){ |
What is the result? A. 0.0 B. Compilation fails. C. A ParseException is thrown by the parse method at runtime. D. A NumberFormatException is thrown by the parse method at runtime. |
答案:B |
題目範圍:例外處理 |
解析: 出現了編譯錯誤,這是因為try/catch 跟if for等等一樣,都是一個block,裡面宣告的區域變數外面都無法使用 這題如果把float 拿到try/catch 的外面宣告,並且賦予初始值,結果便會是0.0 |
第124題: |
Given: 11. static void test() throws RuntimeException{ |
What is the result? A. test end B. Compilation fails. C. test runtime end D. test exception end E. A Throwable is thrown by main at runtime. |
答案:D |
題目範圍:例外處理 |
解析: 這是一個例外處理的演示,例外處理只會被"捕捉"一次,先抓先贏,最後一層的可以優先捕捉 RuntimeException是屬於Exception,因此捕捉成功,印出exception,而不印出runtime |
第125題: |
Given: 33. try{ |
If some sort of exception is thrown at line 34, which output is possible? A. a B. b C. c D. ac E. abc |
答案:D |
題目範圍:例外處理 |
解析: 所謂排序會出現的例外,指的就是NullPointerException,可是個人覺得可能也會是ArrayIndexOutOfBoundsException…先不管 如果捕捉到了NullPointerException ,那麼下一個就不用看了,因為例外只能被捕捉一次 而不論是否有捕捉到例外,在try/catch的block結束後,就會執行finally的內容 |
留言列表