问答题
阅读下列程序,请写出该程序的输出结果。
public class Test35{
public static void main(String[]args){
System.out.println("开始:");
MyThread x=new MyThread(1000,"girl");
MyThread y=new MyThread(300,"boy");
x.start();y.start();
while(x.isAlive()||y.isAlive());
System.out.println("结束.");
}
}
class MyThread extends Thread{
int dt;
String name;
public MyThread(int c,String n){
dt=c;name=n:
}
public void run(){
MyResourceClass.outMsg(this);
}
}
class MyResourceClass{
synchronized static void outMsg(MyThread th){
System.out.println(th. name+" "+"启动.");
for(int i=0;1<2;1++){
System.out.println(th. name+"第"+i+"次活动.");
try{
Thread.sleep(th.dt);
}catch(InterruptedException e){}
}
System.out.println(th.name+" "+"活动完成,");
}
}
【参考答案】
开始:
girl 启动.
girl 第0次活动.
girl 第1次活动.
gi......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)