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.
第1题:
1.publicclassTest{2.publicstaticStringoutput=””;3.4.publicstaticvoidfoo(inti){5.try{6.if(i==1){7.thrownewException();8.}9.output+=“1”;10.}11.catch(Exceptione){12.output+=“2”;13.return;14.}15.finally{16.output+=“3”;17.}18.output+=“4”;19.}20.21.publicstaticvoidmain(Stringargs[]){22.foo(0);23.foo(1);24.25.}26.}Whatisthevalueofthevariableoutputatline23?()
第2题:
4、以下异常处理结构中,错误的是()
A.catch{} finally{}
B.try{} finally{}
C.try{} catch{} finally{}
D.try{} catch{}
第3题:
给定如下Java代码片段,则下列调用方法正确的是()。 Public int count (int i) throws Exception { if (i==0) throw new Exception(“参数不正确!”); return 20/i; }
A.public void useCount(){ count(0); }
B.public void useCount() throws Exception{ count(0); }
C.public void useCount(){ try { count(10); }catch(ArithmeticException e){} }
D.public void useCount(){ try{ count(10); } }
第4题:
给定以下JAVA代码,这段代码编译运行后输出的结果是( )
publicclassTest{
publicstaticintaMethod(inti)throwsException{
try{
returni/10;
}catch(Exceptionex){
thrownewException("exceptioninaaMothod");
}finally{
System.out.print("finally");
}
}
publicstaticvoidmain(String[]args){
try{
aMethod(0);
}catch(Exceptionex){
System.out.print("exceptioninmain");
}
System.out.print("finished");
}
}
A、finallyexceptioninmainfinished
B、exceptioninmainfinally
C、finallyfinished
D、finallyexceptioninmainfinished
第5题:
以下异常处理结构中,错误的是()
A.catch{} finally{}
B.try{} finally{}
C.try{} catch{} finally{}
D.try{} catch{}