填空题
通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程序______。
public class ThreadTest
{
public static void main(String args[ ])
{
Thread t1=new Thread(new Hello());
Thread t2=new Thread(new Hello());
______;
t2.start();
}
}
class Hello implements Runnable
{
int i;
public void run()
{
while(true)
{
System.out.println("Hello"+i++);
if(i==5) break;
}
}
}
【参考答案】
t1.start();[解析] 题中Hello类实现了Runnable接口,在ThreadTest类的main()方法中......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)