publicclassTestOne{publicstaticvoidmain(String[]args)throwsException{Thread.sleep(3000);System.out.println(”sleep”);}}Whatistheresult?() A.Compilationfails.B.Anexceptionisthrownatruntime.C.Thecodeexecutesnormallyandprints“sleep”.D.Thecodeexecutesnormally,butnothingisprinted.

publicclassTestOne{publicstaticvoidmain(String[]args)throwsException{Thread.sleep(3000);System.out.println(”sleep”);}}Whatistheresult?()

A.Compilationfails.

B.Anexceptionisthrownatruntime.

C.Thecodeexecutesnormallyandprints“sleep”.

D.Thecodeexecutesnormally,butnothingisprinted.


相关考题:

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.testB.ExceptionC.Compilationfails.D.NullPointerException

11.staticclassA{12.voidprocess()throwsException{thrownewException();}13.}14.staticclassBextendsA{15.voidprocess(){System.out.println(”B”);}16.}17.publicstaticvoidmain(String[]args){18.newB().process();19.}Whatistheresult?()A.BB.Thecoderunswithnooutput.C.Compilationfailsbecauseofanerrorinline12.D.Compilationfailsbecauseofanerrorinline15.E.Compilationfailsbecauseofanerrorinline18.

classTestA{publicvoidstart(){System.out.println(”TestA”);}}publicclassTestBextendsTestA{publicvoidstart(){System.out.println(”TestB”);}publicstaticvoidmain(String[]args){((TestA)newTestB()).start();}}Whatistheresult?()A.TestAB.TestBC.Compilationfails.D.Anexceptionisthrownatruntime.

publicclassTest{publicstaticvoidmain(String[]args){Stringstr=NULL;System.out.println(str);}}Whatistheresult?() A.NULLB.Compilationfails.C.Thecoderunswithnooutput.D.Anexceptionisthrownatruntime.

publicclassTest{privatestaticint[]x;publicstaticvoidmain(String[]args){System.out.println(x[0]);}}Whatistheresult?() A.0B.nullC.Compilationfails.D.ANullPointerExceptionisthrownatruntime.E.AnArrayIndexOutOfBoundsExceptionisthrownatruntime.

publicclassAextendsThread{A(){setDaemon(true);}publicvoidrun(){(newB()).start();try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Adone”);}classBextendsThread{publicvoidrun(){try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Bdone”);}}publicstaticvoidmain(String[]args){(newA()).start();}}Whatistheresult?()A.AdoneB.BdoneC.AdoneBdoneD.BdoneAdoneE.Thereisnoexceptionthattheapplicationwillprintanything.F.Theapplicationoutputs“Adone”and“Bdone”,innoguaranteedorder.

classMyThreadextendsThread{publicvoidrun(){System.out.println(AAA”);}publicvoidrun(Runnabler){System.out.println(BBB”);}publicstaticvoidmain(String[]args){newThread(newMyThread()).start();}}Whatistheresult?()A.AAAB.BBBC.Compilationfails.D.Thecoderunswithnooutput.

publicclassTest{publicstaticvoidmain(String[]args){intx=0;assert(x>0):“assertionfailed”;System.out.println(“finished”);}}Whatistheresult?() A.finishedB.Compilationfails.C.AnAssertionErroristhrown.D.AnAssertionErroristhrownandfinishedisoutput.

publicclassFoo{publicstaticvoidmain(String[]args){try{return;}finally{System.out.println(Finally”);}}}Whatistheresult?() A.FinallyB.Compilationfails.C.Thecoderunswithnooutput.D.Anexceptionisthrownatruntime.