第136題: |
Given: 11. public static void main(String[] args){ |
What is the result? A. test |
答案:C |
題目範圍:例外處理 |
解析: 因為NullPointerException永遠不會被捕捉到 編譯階段會出現錯誤,原因是這個例外已經在先前被Exception捕捉了 |
第137題: |
Given: 11. class X{public void foo(){System.out.print("X ");}} |
What is the result? A. X, followed by an Exception. |
答案:A |
題目範圍:例外處理 |
解析: 之前提到過Exception必須被處理,否則編譯階段會出錯 但這裡使用的是RuntimeException,這是一個unchecked exceptions |
第138題: |
Which two code fragments are most likely to cause a StackOverflowError? (Choose two.) A. int[] x = {1, 2, 3, 4, 5}; B. static int[] x = {7, 6, 54}; C. for(int y=10; y<10; y++) D. void doOne(int x){doTwo(x);} E. for(int x=0; x<10000000000; x++) F. void counter(int i){counter(++i);} |
答案:DF |
題目範圍:例外處理 |
解析: 當呼叫方法的數量過多時(通常是出現在無限遞迴)就會發生StackOverflowError A.出現的是java.lang.ArrayIndexOutOfBoundsException B.是編譯錯誤 C.不做任何事情,也沒有錯誤 E.會出現編譯錯誤,數值過大超出範圍 |
第139題: |
Given a method that must ensure that its parameter is not null: 11. public void someMethod(Object value){ |
What, inserted at line 12, is the appropriate way to handle a null value? A. assert value == null; B. assert value != null : "value is null"; C. if (value == null){ D. if (value == null){ |
答案:D |
題目範圍:例外處理、Assert用法 |
解析: 雖然B C選項有達到告知的效果 |
第140題: |
Given: 1. public class A{ And given: |
Which two statements are true if a NullPointerException is thrown on line 3 of class C? (Choose two.) A. The application will crash. |
答案:BE |
題目範圍:例外處理 |
解析: 單純的例外傳遞 |