A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Thecodeexecutesnormallyandprints“bar”.
D.Thecodeexecutesnormally,butnothingprints.
第1题:
publicclassThreads4{publicstaticvoidmain(String[]args){newThreads4().go();}publicvoidgo(){Runnabler=newRunnable(){publicvoidrun(){System.out.print(”foo”);}};Threadt=newThread(r);t.start();t.start();}}Whatistheresult?()
A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Thecodeexecutesnormallyandprints?foo”.
D.Thecodeexecutesnormally,butnothingisprinted.
第2题:
A.newThread(){publicvoidrun(){doStuff();}}
B.newThread(){publicvoidstart(){doStuff();}}
C.newThread(){publicvoidstart(){doStuff();}}.run();
D.newThread(){publicvoidrun(){doStuff();}}.start();
E.newThread(newRunnable(){publicvoidrun(){doStuff();}}).run();
F.newThread(newRunnable(){publicvoidrun(){doStuff();}}).start();
第3题:
classMyThreadextendsThread{publicvoidrun(){System.out.println(AAA”);}publicvoidrun(Runnabler){System.out.println(BBB”);}publicstaticvoidmain(String[]args){newThread(newMyThread()).start();}}Whatistheresult?()
A.AAA
B.BBB
C.Compilationfails.
D.Thecoderunswithnooutput.
第4题:
A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Thecodeexecutesandprints“running”.
D.Thecodeexecutesandprints“runningrunning”.
E.Thecodeexecutesandprints“runningrunningrunning”.
第5题:
A.Anexceptionisthrown.
B.Theprogramexistswithoutprintinganything.
C.Anerroratline1causescompilationtofail.
D.Anerroratline2causesthecompilationtofail.
E.“Running”isprintedandtheprogramexits.