-> -> ->
全国2012年1月自学考试《Java语言程序设计(一)》真题(word下载版)(五)
时间:2015-02-09 20:08:26
微信搜索关注"91考试网"公众号,领30元,获取事业编教师公务员等考试资料40G
36.阅读下列程序,请回答以下问题:
(1)程序执行时创建的线程个数。
(2)各线程的名称。
(3)举例给出程序可能的输出结果。
class SeltManaged extends Thread{
int countDown;
public SelfManaged(String name,int c){
countDown=c;
setName(name);start();
}
public void run(){
while(true){
System.out.println(getName()+" ("+countDown+")");
try{
sleep(50);
}catch(InterruptedException e){};
if(--countDown== 0)
return;
}
}
}
public class Test36{
public static void main(String[]args){
for(int i=0;i<2;i++)
new SelfManaged("线程"+String.valueOf(i),2);
}
}
微信搜索关注"91考试网"公众号,领30元,获取公务员事业编教师考试资料40G