condition 1 finally
condition 2 finally
condition 3 finally
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
第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.
第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
第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
第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
第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
第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.无输出
第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题:
如下的代码段中,如果方法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
第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