A.Theprogramrunsandprintsnothing.
B.Theprogramrunsandprints“Finally”.
C.Thecodecomiles.Butanexceptionisthrownatruntime.
D.Thecodewillnotcompilebecausethecatchblockismissing.
第1题:
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
第2题:
A.Theprogramrunsandprints“0”
B.Theprogramrunsandprints“1”
C.Theprogramrunsbutabortswithanexception.
D.Anerror“possibleundefinedvariable”atline4causescompilationtofail.
E.Anerror“possibleundefinedvariable”atline9causescompilationtofail.
第3题:
A.Finally
B.Compilationfails.
C.Thecoderunswithnooutput.
D.Anexceptionisthrownatruntime.
第4题:
publicstaticvoidparse(Stringstr){try{floatf=Float.parseFloat(str);}catch(NumberFormatExceptionnfe){f=0;}finally{System.out.println(f);}}publicstaticvoidmain(String[]args){parse(”invalid”);}Whatistheresult?()
A.0.0
B.Compilationfails.
C.AParseExceptionisthrownbytheparsemethodatruntime.
D.ANumberFormatExceptionisthrownbytheparsemethodatruntime.
第5题:
A.Theprogramrunsandprintsnothing.
B.Theprogramrunsandprints“Finally”
C.Thecodecompiles,butanexceptionisthrownatruntime.
D.Thecodewillnotcompilebecausethecatchblockismissing.