填空题
通过继承Thread创建线程,在主控程序中同时运行两个线程Thread1和Thread2。请在下面横线处填入代码完成此程序。
public class ThreadTest
{
public static void main(String args[])
{
new TestThread("Threadl").start();
【7】
}
}
class TestThread extends Thread()
{
public TestThread(String str)
{
super (str);
}
public void run()
{
for(int i = 0; i<’5; i++)
{
System.out.println(i + .... + getName() + "在运行");
try
{
Sleep(1000);
}catch(InerruptedException e) {}
}
System.out.println(getName() + "已结束");
}
【参考答案】
new TestThread(“Thread2”).start();