package cys;
public class Example9_2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
People personal1,personal2;
StringBuffer str=new StringBuffer();
personal1 = new People("李四",str);
personal2 = new People("王五",str);
personal1.start();
personal2.start();
}
}
class People extends Thread{
StringBuffer str;
People(String s,StringBuffer str){
setName(s);
this.str=str;
}
public void run(){
for(int i=1;i<=3;i++){
str.append(getName()+",");
System.out.println("我叫"+getName()+",名字是:"+str);
try{
sleep(200);
}catch(InterruptedException e){
}
}
}
}