其他

try{intx=0;inty=5/x;}catch(Exceptione){System.out.println(Exception”);}catch(ArithmeticExceptionae){System.out.println(ArithmeticException”);}System.out.println(finished”);Whatistheresult?()A.finishedB.ExceptionC.Compilationfails.D.ArithmeticException

题目
try{intx=0;inty=5/x;}catch(Exceptione){System.out.println(Exception”);}catch(ArithmeticExceptionae){System.out.println(ArithmeticException”);}System.out.println(finished”);Whatistheresult?()

A.finished

B.Exception

C.Compilationfails.

D.ArithmeticException

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

第1题:

下面这段程序的输出结果是error。这种说法对吗? public void compute(){ try{ System.out.println(3/0); } catch(Exception e){ System.out.println('error'); } finally{ System.out.println('final'); } }


第2题:

下列程序的输出结果是( )。 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;i<sizeresult= =-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---1

B.Catch---2

C.Catch---3

D.以上都不对


正确答案:B
B。【解析】本题考查了数组及for循环。本题数组定义的值为5,下标从0~4。数组越界,所以答案为B。

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

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

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

第6题:

try{if((newObject))(.equals((newObject()))){System.out.println(equal”);}else{System.out.println(notequal”);}}catch(Exceptione){System.out.println(exception”);}Whatistheresult?()

A.equal

B.notequal

C.exception

D.Compilationfails.


参考答案:D

第7题:

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

第8题:

( 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

第9题:

阅读下列程序片段。

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。