Given1.publicclassFoo{2.publicstaticvoidmain(String[]args)}3.try{return;}4.finally{Syste.out.printIn(Finally”);}5.}6.}Whatistheresult()? A.Theprogramrunsandprintsnothing.B.Theprogramrunsandprints“Finally”.C.Thecodecomiles.Butanexceptionisthrownatruntime.D.Thecodewillnotcompilebecausethecatchblockismissing.
Given1.publicclassFoo{2.publicstaticvoidmain(String[]args)}3.try{return;}4.finally{Syste.out.printIn(Finally”);}5.}6.}Whatistheresult()?
A.Theprogramrunsandprintsnothing.
B.Theprogramrunsandprints“Finally”.
C.Thecodecomiles.Butanexceptionisthrownatruntime.
D.Thecodewillnotcompilebecausethecatchblockismissing.
相关考题:
1.classA{3.publicStringtoString(){4.return4”;5.}6.}7.classBextendsA{8.publicStringtoString(){9.returnsuper.toString()+3”;10.}11.}12.publicclassTest{13.publicstaticvoidmain(String[]args){14.System.out.printIn(newB());15.}16.}Whatistheresult()?A.Compilationsucceedsand4isprinted.B.Compilation……………isprinted.C.Anerroronline9causecompilationtofail.D.Anerroronline14causecompilationtofail.E.Compilationsucceedsbutanexceptionisthrownatline9.
classCalc{2.publicstaticvoidmain(String[]args){3.try{4.intx=Integer.parseInt(42a);5.//insertcodehere6.System.out.print(oops);7.}8.}9.}下面哪两行分别插入到第五行,会导致输出oops”?() A.}catch(ClassCastExceptionc){B.}catch(IllegalStateExceptionc){C.}catch(NumberFormatExceptionn){D.}catch(IllegalArgumentExceptione){
现有1.classCalc{2.publicstaticvoidmain(String[]args){3.try{4.intx=Integer.parselnt(42a);5.//insertcodehere6.System.out.print(oops);7.}8.}9.}下面哪两行分别插入到第五行,会导致输oops?() A.}catch(IllegalArgumentExceptione){B.}catch(IllegalStateExceptionc){C.}catch(NumbelFormatExceptionn){D.}catch(ClassCastExceptionc){
1.publicclassTarget{2.privateinti=0;3.publicintaddOne(){4.return++i;5.}6.}And:1.publicclassClient{2.publicstaticvoidmain(String[]args){3.System.out.println(newTarget().addOne());4.}5.}WhichchangecanyoumaketoTargetwithoutaffectingClient?()A.Line4ofclassTargetcanbechangedtoreturni++;B.Line2ofclassTargetcanbechangedtoprivateinti=1;C.Line3ofclassTargetcanbechangedtoprivateintaddOne(){D.Line2ofclassTargetcanbechangedtoprivateIntegeri=0;
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.nullB.finallyC.nullfinallyD.Compilationfails.E.finallyexception
publicstaticvoidparse(Stringstr){try{floatf=Float.parseFloat(str);}catch(NumberFormatExceptionnfe){f=0;}finally{System.out.println(f);}}publicstaticvoidmain(String[]args){parse(”invalid”);}Whatistheresult?()A.0.0B.Compilationfails.C.AParseExceptionisthrownbytheparsemethodatruntime.D.ANumberFormatExceptionisthrownbytheparsemethodatruntime.
publicclassX{2.publicstaticvoidmain(String[]args){3.int[]a=newint[1]4.modify(a);5.System.out.printIn(a[0]);6.}7.8.publicstaticvoidmodify(int[]a){9.a[0]++;10.}11.}Whatistheresult?() A.Theprogramrunsandprints“0”B.Theprogramrunsandprints“1”C.Theprogramrunsbutabortswithanexception.D.Anerror“possibleundefinedvariable”atline4causescompilationtofail.E.Anerror“possibleundefinedvariable”atline9causescompilationtofail.
publicclassfoo{publicstaticvoidmain(string[]args)try{return;}finally{system.out.printIn(Finally”);}}Whatistheresult?() A.Theprogramrunsandprintsnothing.B.Theprogramrunsandprints“Finally”C.Thecodecompiles,butanexceptionisthrownatruntime.D.Thecodewillnotcompilebecausethecatchblockismissing.
publicclassFoo{publicstaticvoidmain(String[]args){try{return;}finally{System.out.println(Finally”);}}}Whatistheresult?() A.FinallyB.Compilationfails.C.Thecoderunswithnooutput.D.Anexceptionisthrownatruntime.