itgle.com

publicclassThreads5{publicstaticvoidmain(String[]args){newThread(newRunnable(){publicvoidrun(){System.out.print(”bar”);}}).start();}}Whatistheresult?()A.Compilationfails.B.Anexceptionisthrownatruntime.C.Thecodeexecutesnormallyandprints“bar”.D.Thecodeexecu

题目
publicclassThreads5{publicstaticvoidmain(String[]args){newThread(newRunnable(){publicvoidrun(){System.out.print(”bar”);}}).start();}}Whatistheresult?()

A.Compilationfails.

B.Anexceptionisthrownatruntime.

C.Thecodeexecutesnormallyandprints“bar”.

D.Thecodeexecutesnormally,butnothingprints.


相似考题
更多“publicclassThreads5{publicstaticvoidmain(String[]args){newThread(newRunnable(){publicvoidrun(){System.out.print(”bar”);}}).start();}}Whatistheresult?() ”相关问题
  • 第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.


    参考答案:B

  • 第2题:

    WhichtwocodefragmentswillexecutethemethoddoStuff()inaseparatethread?()

    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();


    参考答案:D, F

  • 第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.


    参考答案:A

  • 第4题:

    publicclassThreads3implementsRunnable{publicvoidrun(){System.out.print(”running”);}publicstaticvoidmain(String[]args){Threadt=newThread(newThreads3());t.run();t.run();t.start();}}Whatistheresult?()

    A.Compilationfails.

    B.Anexceptionisthrownatruntime.

    C.Thecodeexecutesandprints“running”.

    D.Thecodeexecutesandprints“runningrunning”.

    E.Thecodeexecutesandprints“runningrunningrunning”.


    参考答案:E

  • 第5题:

    publicclassFooimplementsRunnable(publicvoidrun(Threadt){system.out.printIn(Running.”);}publicstaticvoidmain(String[]args){newthread(newFoo()).start();})Whatistheresult?()

    A.Anexceptionisthrown.

    B.Theprogramexistswithoutprintinganything.

    C.Anerroratline1causescompilationtofail.

    D.Anerroratline2causesthecompilationtofail.

    E.“Running”isprintedandtheprogramexits.


    参考答案:D