单选题如下代码:  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.pr

题目
单选题
如下代码:  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"); }   }  如果oneMethod正常运行,则输出结果中是?()
A

 condition 1   finally

B

 condition 2   finally

C

 condition 3   finally

D

 finally

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

第1题:

已知如下代码: switch(m) { case 0: System.out.println("Condition0"); case 1: System.out.println("Condition 1"); case 2: System.out.println("Condition 2"); case 3: System.out.println("Condition 3"); break; default: System.out.println("Other cCndition"); } 当m为( )时,"Condition 2"会出现在输出结果中。

A.2

B.0、1

C.0、1、2

D.0、1、2、3


正确答案:C
解析:在switch-case语句中,如果case后没有break,程序会继续执行后面的case语句,直到遇到break或者switch结束。这个程序中只有case 3后才有break,所以当m=0、1、2都将执行case 2后的语句。m=3时,前三个case不满足,所以不执行case 2后的语句,因此选C。

第2题:

publicclassTest{publicstaticvoidaMethod()throwsException{try{thrownewException();}finally{System.out.println(finally”);}}publicstaticvoidmain(Stringargs[]){try{aMethod();}catch(Exceptione){System.out.println(exception”);}System.out.println(finished”);}}Whatistheresult?()

A.finally

B.exceptionfinished

C.finallyexceptionfinished

D.Compilationfails.


参考答案:C

第3题:

如下代码:publicvoidTest(){try{oneMethod();System.out.println("condition1");}catch(ArrayIndexOutOfBoundsExceptione){System.out.println("condition2");}catch(Exceptione){System.out.println("condition3");}finally{System.out.println("finally");}}如果oneMethod正常运行,则输出结果中是?()

A.condition1finally

B.condition2finally

C.condition3finally

D.finally


参考答案:A

第4题:

阅读下列程序片段。 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


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

第5题:

下列代码的执行结果是( )。 public class Test{ public static void main(String[]args){ int[]x={0,1,2,3}; for{int i=0;i<3;1+=2){ try{ systcm.OUt.println(x[i+2]/x[i]+x[i+1]); }catch(ArithmeticException e){ System.OUt.println("errorl"): }catch(Exception e){ System.OUt.println("error2"): } } } }

A.errorl

B.error2

C.errorl orror2

D.2 error2


正确答案:C
C。【解析】当0作为除数时,会产生异常,而ArithmeticException和Exception两类异常都内部被捕捉到。

第6题:

在oneMethod( )方法运行正常的情况下,程序段将输出( )。 public void test( ){ try {oneMethod( ); System.out.println ("condition 1"); }catch (ArratlndexOutOfBoundException e){ System.out.println("condition2"): }catch (Exception e){ System.out.println("condition 3"); }finnally{ System.out.println("finally"): } }

A.condition 1

B.condition2

C.condition 3

D.condition 1 finally


正确答案:D

第7题:

下面程序输出的结果是什么? ( ) public class Quiz2 { public static void main(String args[]) { try {throw new MyException(); }catch(Exception e) { System.out.println("It's caught!"); }finally{ System.out.println("It's finally caught!"); } } } class MyException extends Exception{}

A.It's finally caught!

B.It's caught!

C.It's caught!/It's finally caught!

D.无输出


正确答案:C
解析:本题是对异常处理基本知识的考查。本程序中创建了一个异常类MyException,它的祖先类是Exception。在程序中,程序先发出异常MyException,下面是catch捕获异常,但是catch列表中并没有与之对应的MyExcepfion,但是有一个Exception,它是MyException的祖先类。如果有多种异常需要捕获,在安排catch语句的顺序时要注意,应该首先捕获最特殊的类,然后逐渐一般化。例如,IOExcepfion类是FileNotFoundException类的父类;就应该首先捕获FileNotFoundException异常,然后捕获IOExcepfion异常。所以运行结果是It'scaught!/It'sfinallycaught!

第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题:

如下的代码段中,如果方法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后面的语句总是被执行。

第10题:

阅读下列程序片段 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。

更多相关问题