多选题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"); } } Which will display if oneMethod run normally?()Acondition 1Bcondition 2Ccondition 3Dfinally
多选题
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"); } } Which will display if oneMethod run normally?()
A
condition 1
B
condition 2
C
condition 3
D
finally
参考解析
解析:
如果try块中的语句在执行时发生异常,则执行从该处中断而进入catch块,根据异常的类型进行匹配,最前面的优先进行匹配比较,只要该异常是catch中指定的异常的子类就匹配成功进而执行相应的catch中的内容,而finally块中的内容无论是否发生异常都将被执行。
相关考题:
如下代码: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.condition1finallyB.condition2finallyC.condition3finallyD.finally
阅读下列程序片段。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.HelloB.ArraylndexOutOfBondsExceptionC.ExceptionFinallyD.HelloFinally
已知如下代码: 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.2B.0、1C.0、1、2D.0、1、2、3
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.testB.ExceptionC.Compilationfails.D.NullPointerException
在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 1B.condition2C.condition 3D.condition 1 finally
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.finallyB.exceptionfinishedC.finallyexceptionfinishedD.Compilationfails.
下面程序输出的结果是什么? ( ) 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.无输出
下列代码的执行结果是( )。 public class Test{ public static void main(String[]args){ int[]x={0,1,2,3}; for{int i=0;i3;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.errorlB.error2C.errorl orror2D.2 error2
如下的代码段中,如果方法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 4B.Test1 Test3 Test4C.Test1 Test3D.Test1 Test4
阅读下列程序片段。 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.HelloB.ArraylndexOutOfBondsExceptionC.Exception FinallyD.Hello Finally
阅读下列程序片段 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.HelloB.ArraylndexOutOfBondsExceptionC.Exception FinallyD.Hello Finally
下列程序的输出结果是( )。 Public class Test{ Public static void main(String[]args){ int[]array=(2,4,6,8,10); int size=6; int result=-l: try{ for(int i=0;isizeresult= =-1:) if(array[i]= =20)result=i: } catch(ArithmeticException e){ System.out.println("Catch---1"); } catch(ArraylndexOutOfBoundsException e){ System.out.println("Catch---2"): } catch(Exception e){ System.out.println("Catch---3"): } }A.Catch---1B.Catch---2C.Catch---3D.以上都不对
请阅读下列程序代码,然后将程序的执行结果补充完整。横线处应填写的内容是( )。 程序代码: public class throwsExeeption{ static void Proc(intsel) throws Arithmetic Exception,Array Index Out Of Bounds Exception{ System.out.println("InSituation"+sel); if(sel= =0){ System.OUt.println("noException caught"); return; } else if(sel= =l){ int iArray[]=newint[4]; iArray[1]=3; } } public static void main(String args[]){ try{ Proe(O); Proc(1); } catch(Array Index Out Of Bounds Exception e){ System.out.println("Catch"+e); } finally{ System.out.println("inProcfinally"): } } } 执行结果: In Situation 0 no Exception caught in Proc finallyA.In Situation lB.In SituationC.with CatchD.int iArray l
下列程序的输出结果是( )。 public class Test{ public static void main(String[]args){ int[]array=(2,4,6,8,lO); int size=6; int result =-1: try{ for(int i=0;i(size 8Lresult= = -1;) if(array[i]= =20)result=i: } catch(ArithmeticException e){ System.out.println("Catch- - -l"); } catch(ArraylndexOutOfBoundsException e){ System.out.println("Catch- - -2"); } catch(Exception e){ System.out.println("Catch- - -3");) } }A.Catch- - -1B.Catch- - -2C.Catch- - -3D.以上都不对
在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.pritln("finally"); } }A.condition 1B.condition 2C.condition 3D.condition 1
在oneMethod()方法运行正常的情况下,程序段将输出______。 public void test() { try{ oneMethod(); System.out.println("ndition 1"; } catch (ArrayIndexOutOfVoundsException e){ System.out.println("ondition 2"; } catch (Exception e){ System.out.println("ondition 3"; } finally{ System.out.println ( "inally"; } }A.condition1B.condition2C.condition3D.condition1 finally
下面程序输出的结果是什么? ( ) 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 MyExeeption extends Exception{}A.It's finally caught!B.It's caught!C.It's caught!/It'sfinally caught!D.无输出
在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 1B.condition 2C.condition 3D.condition 1 finally
( 17 )下列程序的输出结果是public class Test{public static void main(String[] args){int [] array={2,4,6,8,10};int size=6;int result=-1;try{for{int i=0;isize result==-1;i++}if(array[i]==20) result=i;}catch(ArithmeticException e){System.out.println( " Catch---1 " );catch(ArrayIndexOutOfBoundsException e){System.out.println( " Catch---2 " );catch(Exception e){System.out.println( " Catch---3 " );}}A ) Catch---1B ) Catch---2C ) Catch---3D )以上都不对
如下代码: 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 finallyB、 condition 2 finallyC、 condition 3 finallyD、 finally
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"); } } Which will display if oneMethod run normally?() A、 condition 1B、 condition 2C、 condition 3D、 finally
public class Test { public static void aMethod() throws Exception { try { throw new Exception(); } finally { System.out.println(“finally”); } } public static void main(String args[]) { try { aMethod(); } catch (Exception e) { System.out.println(“exception”); } System.out.println(“finished”); } } What is the result?() A、 finallyB、 exception finishedC、 finally exception finishedD、 Compilation fails.
public static void main(String[] args) { try { args=null; args[0] = “test”; System.out.println(args[0]); } catch (Exception ex) { System.out.println(”Exception”); } catch (NullPointerException npe) { System.out.println(”NullPointerException”); } } What is the result?() A、 testB、 ExceptionC、 Compilation fails.D、 NullPointerException
单选题public static void main(String[] args) { try { args=null; args[0] = “test”; System.out.println(args[0]); } catch (Exception ex) { System.out.println(”Exception”); } catch (NullPointerException npe) { System.out.println(”NullPointerException”); } } What is the result?()A testB ExceptionC Compilation fails.D NullPointerException
单选题public class Test { public static void aMethod() throws Exception { try { throw new Exception(); } finally { System.out.println(“finally”); } } public static void main(String args[]) { try { aMethod(); } catch (Exception e) { System.out.println(“exception”); } System.out.println(“finished”); } } What is the result?()A finallyB exception finishedC finally exception finishedD Compilation fails.
单选题阅读下列程序片段: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()方法的运行结果将是( )。AhelloBArrayIndexOutOfBoundExceptionCException finallyDhello finally
单选题如下代码: 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 finallyB condition 2 finallyC condition 3 finallyD finally