2016年計算機二級《JAVA》章節(jié)練習題:異常和斷言

字號:

第6章 異常和斷言
    1[單選題]哪個關鍵字可以拋出異常? (  )
    A.transientB.finallyC.throwD.static
    參考答案:C
    2[單選題]給出一段程序,試判斷哪個是正確的結果(  )
    public class rtExcept{
    public static void throwit(){
    System.out.print(“throwit”);
    throw new RuntimeException();
    }
    public static void main(String [] aa){
    try{
    System.out.print(“hello “);
    throwit(); }
    catch(Exception re){
    System.out.print(“caught ”); }
    finally{
    System.out.print(“finally ”); }
    System.out.print(“after ”);
    }
    }
    A.hello throwit caught
    B.hello throwit caught finally after
    C.hello throwit RuntimeException after
    D.hello throwit caught finally after RuntimeException
    參考答案:B
    3[單選題]下列敘述中正確的是
    A.軟件測試應該由程序開發(fā)者來完成
    B.程序經調試后一般不需要再測試
    C.軟件維護只包括對程序代碼的維護
    D.以上三種說法都不對
    參考答案:D
    4[單選題]
    
    參考答案:B
    5[單選題]給出一段程序,試判斷哪個是正確的結果(  )
    public class myprogram{
    public static void main (String args[]){
    try{
    System.out.print(“Hello world ”); }
    finally{
    System.out.println(“Finally executing”); }
    }
    }
    A.無法編譯,因為沒有指定異常
    B.無法編譯,因為沒有catch子句
    C.Hello world
    D.Hello world Finally executing
    參考答案:B
    6[填空題]數據獨立性分為邏輯獨立性與物理獨立性。當數據的存儲結構改變時,其邏輯結構可以不變,因此,基于邏輯結構的應用程序不必修改,稱為 。
    參考解析:邏輯獨立性
    7[單選題]
    
    參考答案:D
    8[單選題]在java的一個異常處理中,哪個語句塊可以有多個 (  )
    A.catch B.finally C.try D.throws
    參考答案:A
    9[單選題]為了提高測試的效率,應該
    A.隨機選取測試數據
    B.取一切可能的輸入數據作為測試數據
    C.在完成編碼以后制定軟件的測試計劃
    D.集中對付那些錯誤群集的程序
    參考答案:D
    10[單選題]異常包含下列哪些內容(  )
    A.程序中的語法錯誤
    B.程序的編譯錯誤
    C.程序執(zhí)行過程中遇到的事先沒有預料到的情況
    D.程序事先定義好的可能出現的意外情況
    參考答案:A
    11[單選題]在異常處理中,如釋放資源、關閉文件、關閉數據庫等由(  )來完成。
    A.try子句B.catch子句C.finally子句 D.throw子句
    參考答案:C
    12[單選題]當方法遇到異常又不知如何處理時,下列哪種說法是正確的(  )。
    A.捕獲異常B.拋出異常C.聲明異常D.嵌套異常
    參考答案:B
    13[單選題]下列哪個選項是Java調試器,如果編譯器返回程序代碼的錯誤,可以用它對程序進行調試?
    A.javexe B.javadoexe C.jdexe D.javaproexe
    參考答案:C
    14[單選題]給出下列的代碼,哪行在編譯時可能會有錯誤?
    ① public void modify(){
    ② int i, j, k;
    ③ i = 100;
    ④ while ( i > 0 ){
    ⑤ j = i * 2;
    ⑥ System.out.println (" The value of j is " + j );
    ⑦ k = k + 1;
    ⑧ }
    ⑨ }
    A.line 4 B.line 6 C.line 7 D.line 8
    參考答案:C
    16[單選題]下列代碼的執(zhí)行結果是
    public class Test
    {
    public int aMethod()
    {
    static int i=0;
    i++;
    System.out.println(i);
    }
    public static void main(String args[])
    {
    Test test = new Test();
    test.aMethod();
    }
    }
    A.編譯錯誤 B.0 C.1 D.運行成功,但不輸出
    參考答案:A
    17[單選題]下列代碼的執(zhí)行結果是
    public class Test
    {
    public int aMethod()
    {
    static int i=0;
    i++;
    System.out.println(i);
    }
    public static void main(String args[])
    {
    Test test = new Test();
    test.aMethod();
    }
    }
    A.編譯錯誤 B.0 C.1 D.運行成功,但不輸出
    參考答案:B
    18[單選題]下列常見的系統(tǒng)定義的異常中,哪個是數組越界異常?
    A.ArrayIndexOutOfBoundsException
    B.IOException
    C.NullPointerException
    D.ArithmeticException
    參考答案:A
    19[單選題]在oneMethod()方法運行正常的情況下,程序段將輸出什么?
    public void test()
    {
    try { oneMethod();
    System.out.println("condition 1");
    } catch (ArrayIndexOutOfBoundsException e)
    {
    System.out.println("condition 2");
    } catch(Exception e)
    {
    System.out.println("condition 3");
    } finally
    {
    System.out.println("finally");
    }
    }
    A.condition 1 B.condition 2 C.condition 3 D.condition 1
    finally
    參考答案:D
    20[單選題]下列常見的系統(tǒng)定義的異常中,哪個是輸入、輸出異常?
    A.ClassNotFoundException
    B.IOException
    C.FileNotFoundException
    D.UnknownHostException
    參考答案:B
    22[填空題]診斷和改正程序中錯誤的工作通常稱為    。
    參考解析:調試或程序調試或軟件調試或Debug(英文字母大小寫均可)或調試程序或調試軟件
    23[填空題]程序測試分為靜態(tài)分析和動態(tài)測試。其中 是指不執(zhí)行程序,而只是對程序文本進行檢查,通過閱讀和討論,分析和發(fā)現程序中的錯誤。
    參考解析:靜態(tài)分析
    24[填空題]通常,將軟件產品從提出、實現、使用維護到停止使用退役的過程稱為______。
    參考解析:軟件生命周期
    25[填空題]問題處理方案的正確而完整的描述稱為    。
    參考解析:算法或程序或流程圖