itgle.com

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

题目
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”.


相似考题
更多“publicclassThreads3implementsRunnable{publicvoidrun(){System.out.print(”running”);}publicstaticvoidmain(String[]args){Threadt=newThread(newThreads3());t.run();t.run();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题:

    publicclassFooimplementsRunnable(3.publicvoidrun(Threadt){4.system.out.printIn(Running.”);5.}6.publicstaticvoidmain(String[]args){7.newthread(newFoo()).start();8.)9.)Whatistheresult?()

    A.Anexceptionisthrown.

    B.Theprogramexistswithoutprintinganything.

    C.Anerroratline1causescompilationtofail.

    D.Anerroratline6causesthecompilationtofail.

    E.“Running”isprintedandtheprogramexits.


    参考答案:C

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


    正确答案:C

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


    参考答案:A

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