classThreadBothextendsThreadimplementsRunnable{publicvoidrun(){System.out.print(hihi);}publicstaticvoidmain(String[]args){Threadt1=newThreadBoth();Threadt2=newThread(t1);t1.run();t2.run();}}结果为:()A.hiB.hihiC.编译失败D.代码运行,但无输出结果

classThreadBothextendsThreadimplementsRunnable{publicvoidrun(){System.out.print("hi&q

classThreadBothextendsThreadimplementsRunnable{publicvoidrun(){System.out.print("hi");}publicstaticvoidmain(String[]args){Threadt1=newThreadBoth();Threadt2=newThread(t1);t1.run();t2.run();}}结果为:()

A.hi

B.hihi

C.编译失败

D.代码运行,但无输出结果


相关考题:

在PowerPoint 2003中,删除幻灯片的操作可以是()。A.单击常用工具栏中的quot粘贴quot按钮B.选择quot编辑quot菜单中的quot删除幻灯片quot选项C.选择quot编辑quot菜单中的quot清除quot选项D.单击常用工具栏中的quot复制quot按钮

classOrderimplementsRunnable{publicvoidrun(){try{Thread.sleep(2000);}catch(Exceptione){}System.out.print(in);}publicstaticvoidmain(String[]args){Threadt=newThread(newOrder());t.start();System.out.print(pre);try{t.join();}catch(Exceptione){}System.out.print(post);}}可产生哪两项结果?()A.inpreB.preinC.inprepostD.preinpost

classWorkimplementsRunnable{Threadother;Work(Threadother){this.other=other;}publicvoidrun(){try{other.join();}catch(Exceptione){}System.out.print(afterjoin);}}classLaunch{publicstaticvoidmain(String[]args){newThread(newWork(Thread.currentThread())).start();System.out.print(afterstart);}}结果为:()A.afterjoinB.afterstartC.afterjoinafterstartD.afterstartafterjoin

classOrderimplementsRunnable{publicvoidrun(){try{Thread.sleep(2000);}catch(Exceptione)System.out.print(in);publicstaticvoidmain(String[]args){Threadt=newThread(newOrder());t.start();System.out.print(pre);try{t.join();}catch(Exceptione){}System.out.print(post);可产生哪两项结果?()A.preinpostB.preinC.inpostpreD.inprepostE.prepostin

publicclassTwoThreads{privatestaticObjectresource=newObject();privatestaticvoiddelay(longn){try{Thread.sleep(n);}catch(Exceptione){System.out.print(”Error);}}publicstaticvoidmain(String[]args){System.out.print(”StartMain);newThread1().start();delay(1000);Threadt2=newThread2();t2.start();delay(1000);t2.interruptdelay(1000);System.out.print(”EndMain);}staticclassThread1extendsThread{publicvoidrun(){synchronized(resource){System.out.print(”Startl);delay(6000);System.out.print(”End1);}}}staticclassThread2extendsThread{publicvoidrun(){synchronized(resource){System.out.print(”Start2);delay(2000);System.out.print(”End2);}}}}Assumethatsleep(n)executesinexactlymmilliseconds,andallothercodeexecutesinaninsignificantamountoftime.Whatistheoutputifthemain()methodisrun?()

publicclassTestOneimplementsRunnable{publicstaticvoidmain(String[]args)throwsException{Threadt=newThread(newTestOne());t.start();System.out.print(”Started”);t.join();System.out.print(”Complete”);}publicvoidrun(){for(inti=0;i4;i++){System.out.print(i);}}}Whatcanbearesult?()A.Compilationfails.B.Anexceptionisthrownatruntime.C.Thecodeexecutesandprints“StartedComplete”.D.Thecodeexecutesandprints“StartedComplete0123”.E.Thecodeexecutesandprints“Started0l23Complete”.

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.

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

publicclassSyncTest{publicstaticvoidmain(Stringargs){finalStringBuffers1=newStringBuffer();finalStringBuffers2=newStringBuffer();newThread(){publicvoidrun(){synchronized(s1){s2.append(A”);synchronized(s2){s2.append(B”);System.out.print(s1);System.out.print(s2);}}}}.start();newThread(){publicvoidrun(){synchronized(s2){s2.append(C”);synchronized(s1){s1.append(D”);System.out.print(s2);System.out.print(s1);}}}}.start();}}Whichtwostatementsaretrue?()