A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Thecodeexecutesandprints“running”.
D.Thecodeexecutesandprints“runningrunning”.
E.Thecodeexecutesandprints“runningrunningrunning”.
第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.Anexceptionisthrown.
B.Theprogramexistswithoutprintinganything.
C.Anerroratline1causescompilationtofail.
D.Anerroratline6causesthecompilationtofail.
E.“Running”isprintedandtheprogramexits.
第3题:
阅读下面程序 public class Test implements Runnable { public static void main(String[] args) { ______ t.start(); } public void run() { System.out.println("Hello!"); } } 程序中下画线处应填入的正确选项是
A.Test t=new Test();
B.Thread t=new Thread();
C.Thread t=new Thread(new Test());
D.Test t=new Thread();
第4题:
GiventhatastaticmethoddoIt()inaclassWorkrepresentsworktobedone,whatblockofcodewillsucceedinstartinganewthreadthatwilldothework?
CODEBLOCKa:
Runnabler=newRunnable(){
publicvoidrun(){
Work.doIt();
}
};
Threadt=newThread(r);
t.start();
CODEBLOCKb:
Threadt=newThread(){
publicvoidstart(){
Work.doIt();}};
t.start();
CODEBLOCKc:
Runnabler=newRunnable(){
publicvoidrun(){
Work.doIt();
}
};
r.start();
CODEBLOCKd:
Threadt=newThread(newWork());
t.start();
CODEBLOCKe:
Runnablet=newRunnable(){
publicvoidrun(){
Work.doIt();
}
};
t.run();
第5题:
A.Anexceptionisthrown.
B.Theprogramexistswithoutprintinganything.
C.Anerroratline1causescompilationtofail.
D.Anerroratline2causesthecompilationtofail.
E.“Running”isprintedandtheprogramexits.