Runnabler=newRunnable(){publicvoidrun(){System.out.print(”Cat”);}};Threadt=newThread(r){publicvoidrun(){System.out.print(”Dog”);}};t.start();Whatistheresult?()A.CatB.DogC.Compilationfails.D.Thecoderunswithnooutput.E.Anexceptionisthrownatruntime.

题目
Runnabler=newRunnable(){publicvoidrun(){System.out.print(”Cat”);}};Threadt=newThread(r){publicvoidrun(){System.out.print(”Dog”);}};t.start();Whatistheresult?()

A.Cat

B.Dog

C.Compilationfails.

D.Thecoderunswithnooutput.

E.Anexceptionisthrownatruntime.


相似考题
参考答案和解析
参考答案:B
更多“Runnabler=newRunnable(){publicvoidrun(){System.out.print(”Cat”);}};Threadt=newThread(r){publicvoidrun(){System.out.print(”Dog”);}};t.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题:

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


    参考答案:A