A.go
B.gogo
C.gogogo
D.go之后跟着一个异常
第1题:
A.Cat
B.Dog
C.Compilationfails.
D.Thecoderunswithnooutput.
E.Anexceptionisthrownatruntime.
第2题:
A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Thecodeexecutesandprints“running”.
D.Thecodeexecutesandprints“runningrunning”.
E.Thecodeexecutesandprints“runningrunningrunning”.
第3题:
A.Tht=newTh();t.start();
B.newTh.start();
C.Threadt=newThread(newTh());t.start();
D.Tht=newTh();t.run();
第4题:
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.
第5题:
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();