问答题
下面是一个利用集成class Thread产生线程的例子,请完成其中run()方法(画线处)的编写。
public class SimpleThread extends Thread{
private static int threadCount=0;
private int countDown=5;
private int threadNumber=0;
public SimpleThread(){
threadCount++;
threadNumber=threadCount;
System.out.println("making"+threadCount);
}
______{
______{
______;
______;
}
}
public static void main(String[]args){
for(int i=0;i<5;i++)new SimpleThread().start();
System.out.println("All Threads started");
}
}
【正确答案】public void run(){
while(true){
System.out.println("Thread"+threadNumber+"("+countDown+")");
if(--countDown==0)return;
}
}
【答案解析】