阅读下列程序片段。 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
第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) { }
第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
第4题:
阅读下列程序片段。如果sayHello( )方法正常运行,则test( )方法的运行结果将是( )。
A.Hello
B.ArrayIndexOutOfBondsException
C.ExceptionFinally
D.HelloFinally
第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
第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
第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
第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。【解析】sayHello方法正常运行则程序不抛出异常,并执行finally,所以为D。
第9题:
A.没有catch或finally块
B.没有抛出异常的代码不能出现在try代码块内
C.如果没有catch块而使用try,main()会总是抛出异常.
D.classA没有throwsIOException