niusouti.com

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){}S

题目

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.


相似考题
参考答案和解析
参考答案:B
更多“publicclassAextendsThread{A(){setDaemon(true);}publicvoidrun(){(newB()).start();try{Thread ”相关问题
  • 第1题:

    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.afterjoin

    B.afterstart

    C.afterjoinafterstart

    D.afterstartafterjoin


    参考答案:D

  • 第2题:

    现有:

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

    }

    }

    以下哪两项是正确的?()


    参考答案:B, F

  • 第3题:

    请阅读下面程序,说明该程序创建线程使用的方法是( )。 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.start

    D.t2.start


    正确答案:B
    B。【解析】本题考查线程的创建。在Java中,创建线程有两种方法:①通过实现Runnable接口创建线程。Runnable接口中只定义了一个run方法作为线程体。②通过继承Thread类创建线程,Thread类本身实现了Runnable接口。创建的新的线程不会自动运行,必须调用start方法才能运行。本题中HolloWorld类实现了Runnable接口。

  • 第4题:

    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.preinpost

    B.prein

    C.inpostpre

    D.inprepost

    E.prepostin


    参考答案:A, D

  • 第5题:

    下列程序的执行结果是______。 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-0

    B.Thread-1

    C.Thread-0

    D.Thread-1 Thread-1 Thread-0


    正确答案:A
    解析:类A5继承了Thread类,并且重写了Thread类的run()方法,调用本线程的getName()方法打印出系统给本线程定义的名称。在main()方法中,a1和a2是A5的对象,它们对应的系统默认的线程名称分别是Thread—0和Thread—1,根据类A5的类变量b的布尔值控制哪一个线程调用start()方法,这里应该是a1线程被调度执行。