计算机二级

阅读下列程序片段。 Public void test{ Try{ sayHello; system.out.println("hello"): }catch(ArraylndexOutOfBoundException e){ System.out.println("ArraylndexOutOfBoundExcep— tion"); }catch(Exception e){ System.out.println("Exception"): }finally{ System.Out.println("fin

题目

阅读下列程序片段。 Public void test{ Try{ sayHello; system.out.println("hello"): }catch(ArraylndexOutOfBoundException e){ System.out.println("ArraylndexOutOfBoundExcep— tion"); }catch(Exception e){ System.out.println("Exception"): }finally{ System.Out.println("finally"); } } 如果sayHello方法正常运行,则test方法的运行结果将是( )。

A.Hello

B.ArraylndexOutOfBondsException

C.Exception Finally

D.Hello Finally

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

如果下列的方法能够正常运行,在控制台上将不显示()选项。 public void example() { try{ unsafe();     System.out.println("Test1"); }catch(SafeException e) { System.out.println("Test2"); }finally{ System.out.println("Test3"); } System.out.println("Test4"); }

A.Test1

B.Test2

C.Test3

D.Test4


ACD

第2题:

为了向文件hello.txt尾部追加数据,下列哪个是正确创建指向hello.txt的流()

A.try{ OutputStream out=new FileOutputStream("hello.txt"); }catch(IOException e) { }

B.try{ OutputStream out=new FileOutputStream("hello.txt",true); }catch(IOException e) { }

C.try{ OutputStream out=new FileOutputStream("hello.txt",false); }catch(IOException e) { }

D.try{ OutputStream out=new OutputStream("hello.txt",true); }catch(IOException e) { }


C

第3题:

阅读下列程序片段 Publicvoidtest(){ Try{ sayHello(); system.out.println(“hello"); }catch(ArrayIndexOutOfBoundExceptione){ System.out.println(“ArraylndexOutOfBoundException”); }catch(Exceptione){ System.out.println(“Exception”); }finally{ System.out.println(“finally”); } } 如果sayHello()方法正常运行,则test()方法的运行结果将是( )。

A.Hello

B.ArraylndexOutOfBondsException

C.Exception Finally

D.Hello Finally


正确答案:D
解析:sayHello()方法正常运行则程序不抛出异常,并走finally,所以为D。

第4题:

阅读下列程序片段。如果sayHello( )方法正常运行,则test( )方法的运行结果将是( )。

A.Hello

B.ArrayIndexOutOfBondsException

C.ExceptionFinally

D.HelloFinally


正确答案:D
sayHello()方法正常运行则程序不抛出异常,并执行finally,所以为符合选项D。

第5题:

如下的代码段中,如果方法unsafe()正常运行,那么结果是( )。 public void example() { try { unsafe(); System.out.println("Testl"); }catch(SafeException e) { System.out.println("Test 2"); }finally{ System.out.println("Test 3'); } System.out.println("Test 4"); }

A.Test 3 Test 4

B.Test1 Test3 Test4

C.Test1 Test3

D.Test1 Test4


正确答案:B
解析:在正常情况下,打印Test1、Test3、Test4:在产生可捕获异常时,打印Test2、Test3、Test4;在产生不可捕获异常时,打印Test3,然后终止程序。注意finally后面的语句总是被执行。

第6题:

publicstaticvoidmain(String[]args){try{args=null;args[0]=test”;System.out.println(args[0]);}catch(Exceptionex){System.out.println(”Exception”);}catch(NullPointerExceptionnpe){System.out.println(”NullPointerException”);}}Whatistheresult?()

A.test

B.Exception

C.Compilationfails.

D.NullPointerException


参考答案:C

第7题:

( 26 )阅读下列程序片段

Public void test(){

Try{

sayHello();

system.out.println( “ hello ” );

} catch (ArrayIndexOutOfBoundException e) {

System.out.println( “ ArrayIndexOutOfBoundException ” );

}catch(Exception e){

System.out.println( “ Exception ” );

}finally {

System.out.println( “ finally ” );

}

}

如果 sayHello( ) 方法正常运行,则 test( ) 方法的运行结果将是

A) Hello

B) ArrayIndexOutOfBondsException

C) Exception

Finally

D) Hello

Finally


正确答案:D

第8题:

阅读下列程序片段。

Public void test{

Try{

sayHello;

system.out.println("hello"):

}catch(ArraylndexOutOfBoundException e){

System.out.println("ArraylndexOutOfBoundExcep—

tion");

}catch(Exception e){

System.out.println("Exception"):

}finally{

System.Out.println("finally");

}

}

如果sayHello方法正常运行,则test方法的运行结果将是( )。

A.Hello

B.ArraylndexOutOfBondsException

C.ExceptionFinally

D.HelloFinally


正确答案:D

D。【解析】sayHello方法正常运行则程序不抛出异常,并执行finally,所以为D。

第9题:

考虑下列Java代码:ClasscA{Publicstaticvoidmain(String[]args){Try{System.out.println(hello,world”)}}}其中错误的是()。

A.没有catch或finally块

B.没有抛出异常的代码不能出现在try代码块内

C.如果没有catch块而使用try,main()会总是抛出异常.

D.classA没有throwsIOException


参考答案:B