publicclassAextendsThread{A(){setDaemon(true);}publicvoidrun(){(newB()).start();try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Adone”);}classBextendsThread{publicvoidrun(){try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Bdone”);}}publicstaticvoidmain(String[]args){(newA()).start();}}Whatistheresult?()A.AdoneB.BdoneC.AdoneBdoneD.BdoneAdoneE.Thereisnoexceptionthattheapplicationwillprintanything.F.Theapplicationoutputs“Adone”and“Bdone”,innoguaranteedorder.

publicclassAextendsThread{A(){setDaemon(true);}publicvoidrun(){(newB()).start();try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Adone”);}classBextendsThread{publicvoidrun(){try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Bdone”);}}publicstaticvoidmain(String[]args){(newA()).start();}}Whatistheresult?()

A.Adone

B.Bdone

C.AdoneBdone

D.BdoneAdone

E.Thereisnoexceptionthattheapplicationwillprintanything.

F.Theapplicationoutputs“Adone”and“Bdone”,innoguaranteedorder.


相关考题:

( 24 )请阅读下面程序public class ThreadTest {public static void main ( String args[ ]){Thread t1 = new Thread ( new Hello ()):Thread t2 = new Thread ( new Hello ()):t l .start ():t2.start ();}}class Hello implements Runnable {int i ;public void run (){while ( true ) {System.out.println ( "Hello"+i++ ) ;if ( i=5 ) break :}}}该程序创建线程使用的方法是()A )继承 Thread 类B )实现 Runnable 接口C ) t l.start ()D ) t2.start ()

请阅读下面程序 public class ThreadTest{ public static void main(String args[]) ( Thread t1=new Thread(new Hello()); Thread t2=new Thread(new Hello()); t1.start(); t2.start(); } } class Hello implements Runnable { int i; public void run() { while(true) { System.out.prinfin("Hello"+i++); if(i=5) break; } } } 该程序创建线程使用的方法是A.继承Thread类B.实现Runnable接口C.t1.start()D.t2.start()

classWaitingimplementsRunnable{booleanflag=false;publicsynchronizedvoidrun(){if(flag){flag=false;System.out.print(1);try{this.wait();}catch(Exceptione){}System.out.print(2);}else{flag=true;System.out.print(3);try{Thread.sleep(2000);}catch(Exceptione){}System.out.print(4);notify();}}publicstaticvoidmain(String[]args){Waitingw=newWaiting();newThread(w).start();newThread(w).start();}}以下哪两项是正确的?()

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

现有:classWaitingimplementsRunnable{booleanflag=false;publicsynchronizedvoidrun(){if(flag){flag=false;System.out.print(1);try{this.wait();)catch(Exceptione){}System.out.print(2);}else{flag=true;System.out.print(3);try{Thread.sleep(2000);}catch(Exceptione){}System.out.print(4);notify();}}publicstaticvoidmain(String[]args){Waitingw=newWaiting();newThread(w).start();newThread(w).start();}}以下哪两项是正确的?()

下列程序的执行结果是______。 class A5 extends Thread { boolean b; A5 (boolean bb) { b = bb; } public void run() { System.out.println(this.getName() + "运行"); } } public class Testl5 { public static void main(String[] args) { A5 a1 = new A5(true); A5 a2 = new A5(false); if(a1.b) A1.start(); if (a2 .b) A2.start(); } }A.Thread-0B.Thread-1C.Thread-0D.Thread-1 Thread-1 Thread-0

请阅读下面程序,说明该程序创建线程使用的方法是( )。 public class ThreadTest { public static void main(String args[]) { Thread tl=new Thread(new HolloWorld); Thread t2=new Thread(new HolloWorld); tl.start; t2.Start; } } class HolloWorld implements Runnable { int i; public void run { while(true) { System.out.println("HolloWorld"+i++); if(i= =5)break; } } }A.继承Thread类B.实现Runnable接口C.tl.startD.t2.start