问题 填空题

通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程序______。
publicclass ThreadTest

publicstaticvoid main(Stringargs[])

Threadt1=newThread(newHello()):
Threadt2=newThread(newHellO());
T2.start();


classHelloimplementsRunnable

intI;
publicvoidIUB()

while(true)

System.out.println(“Hello”+i++);
If(i==5)break;


答案

参考答案:t1.start():

解析: 题中Hello类实现了Runnable接口,在ThreadTest类的main()方法中,Hello类的两个实例对象分别创建了t1、t2两个线程,并将线程启动。那么程序体中的画线处应该是将t1线程启动(调用方法start())。

单项选择题
名词解释