请阅读下面程序 publicclassThreadTest{ publicstaticvoidmain(Stringargs[])throwsEx— ception{ inti=0l Hellot=newHello( ); _____; while(

admin2013-12-02  7

问题 请阅读下面程序
publicclassThreadTest{
publicstaticvoidmain(Stringargs[])throwsEx—
ception{
inti=0l
Hellot=newHello(    );
_____;
while(true)(
System.OUt.println(“GoodMorning”+i++);
if(i==2&&t.isAlive(    ))(
System.Out.println(“MainwaitingforHel—
lo!”);
t.join(    );//等待t运行结束
}
if(i==5)breakI)
}
}
classHelloextendsThread{
inti;
publicvoidrun(    ){
while(true){
System.out.println(“Hello”+i++);
if(i==5)breakI)))
为使该程序正确执行,下画线处的语句应是(    )。

选项 A、t.sleep(    )
B、t.yield(    )
C、t.interrupt(    )
D、t.start(    )

答案D

解析 程序中通过继承Thread类来创建线程,而Java中新创建的线程不会自动运行,必须调用线程的startO方法,才能运行该线程。
转载请注明原文地址:https://www.kaotiyun.com/show/QLID777K
0

相关试题推荐
最新回复(0)