classFlow{publicstaticvoidmain(String[]args){try{System.out.print("before");doRiskyThing();System.out.print("after");}catch(Exceptionfe){System.out.print("catch");}System.out.println("done");}publicstaticvoiddoRiskyThing()throwsException{//thiscodereturnsunlessitthrowsanException}}可能会产生下面哪两项结果?()
A.before
B.beforecatch
C.beforeafterdone
D.beforecatchdone
第1题:
staticvoidtest()throwsRuntimeException{try{System.out.print(”test);thrownewRuntimeException();}catch(Exceptionex){System.out.print(”exception);}}publicstaticvoidmain(String[]args){try{test();}catch(RuntimeExceptionex){System.out.print(”runtime);}System.out.print(”end);}Whatistheresult?()
A.testend
B.Compilationfails.
C.testruntimeend
D.testexceptionend
E.AThrowableisthrownbymainatruntime.
第2题:
staticvoidtest()throwsError{if(true)thrownewAssertionError();System.out.print(”test);}publicstaticvoidmain(String[]args){try{test();}catch(Exceptionex){System.out.print(”exception);}System.out.print(”elld);}Whatistheresult?()
A.end
B.Compilationfails.
C.exceptionend
D.exceptiontestend
E.AThrowableisthrownbymain.
F.AnExceptionisthrownbymain.
第3题:
publicclassX{publicstaticvoidmain(String[]args){try{badMethod();System.out.print(A”);}catch(Exceptionex){System.out.print(B”);}finally{System.out.print(C”);}System.out.print(D”);}publicstaticvoidbadMethod(){}}Whatistheresult?()
A.AC
B.BD
C.ACD
D.ABCD
E.Compilationfails.
第4题:
staticvoidtest(){try{Stringx=null;System.out.print(x.toString()+);}finally{System.out.print(finally);}}publicstaticvoidmain(String[]args){try{test();}catch(Exceptionex){System.out.print(”exception);}}Whatistheresult?()
A.null
B.finally
C.nullfinally
D.Compilationfails.
E.finallyexception
第5题:
publicclassX{publicstaticvoidmain(String[]args){try{badMethod();System.out.print(A”);}catch(Exceptionex){System.out.print(B”);}finally{System.out.print(C”);}System.out.print(D”);}publicstaticvoidbadMethod(){thrownewRuntimeException();}}Whatistheresult?()
A.AB
B.BC
C.ABC
D.BCD
E.Compilationfails.