classOrderimplementsRunnable{publicvoidrun(){try{Thread.sleep(2000);}catch(Exceptione)System.out.print("in");publicstaticvoidmain(String[]args){Threadt=newThread(newOrder());t.start();System.out.print("pre");try{t.join();}catch(Exceptione){}System.out.print("post");可产生哪两项结果?()
A.preinpost
B.prein
C.inpostpre
D.inprepost
E.prepostin
第1题:
classBirds{publicstaticvoidmain(String[]args){try{thrownewException();}catch(Exceptione){try{thrownewException();}catch(Exceptione2){System.out.print("inner");}System.out.print("middle");}System.out.print("outer");}}结果为:()
A.inner
B.innerouter
C.middleouter
D.innermiddleouter
第2题:
现有:classThreadExceptimplementsRunnable{publicvoidrun(){thrownewRuntimeException("exception");}publicstaticvoidmain(String[]args){newThread(newThreadExcept()).start();try{intx=Integer.parseInt(args[0]);Thread.sleep(x);System.out.print("main");}catch(Exceptione){}}}和命令行:javaThreadExcept1000哪一个是结果?()
A.main
B.编译失败
C.代码运行,但没有输出
D.mainjava.lang.RuntimeException:exception
第3题:
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.Adone
B.Bdone
C.AdoneBdone
D.BdoneAdone
E.Thereisnoexceptionthattheapplicationwillprintanything.
F.Theapplicationoutputs“Adone”and“Bdone”,innoguaranteedorder.
第4题:
classWorkimplementsRunnable{Threadother;Work(Threadother){this.other=other;}publicvoidrun(){try{other.join();}catch(Exceptione){}System.out.print("afterjoin");}}classLaunch{publicstaticvoidmain(String[]args){newThread(newWork(Thread.currentThread())).start();System.out.print("afterstart");}}结果为:()
A.afterjoin
B.afterstart
C.afterjoinafterstart
D.afterstartafterjoin
第5题:
现有:
classWaitingimplementsRunnable{
booleanflag=false;
publicsynchronizedvoidrun(){
if(flag){
flag=false;
System.out.print("1");
try{this.wait();)catch(Exceptione){}
System.out.print("2");
}
else{
flag=true;
System.out.print("3");
try{Thread.sleep(2000);}catch(Exceptione){}
System.out.print("4");
notify();
}
}
publicstaticvoidmain(String[]args){
Waitingw=newWaiting();
newThread(w).start();
newThread(w).start();
}
}
以下哪两项是正确的?()