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); } }
|