public class xiancheng2 {
public static void main(String[] args) {
shuxing sh=new shuxing();
Input in=new Input(sh);
Output out=new Output(sh);
Thread t1=new Thread(in);
Thread t2=new Thread(out);
t1.start();
t2.start();
}
}
class shuxing{
String name;
String age;
}
class Input implements Runnable{
private shuxing s;
Input(shuxing s){
this.s=s;
}
public void run(){
int x=0;
while(true){
if(x==0){
s.name="asdf";
s.age="nv";
}
else{
s.name="明明";
s.age="男";
}
x=(x+1)%2;
}
}
}
class Output implements Runnable{
private shuxing s;
Output(shuxing s){
this.s=s;
}
public void run(){
System.out.println(s.name+"****"+s.age);
}
}
这是整体代码 没有相同的类名啊 就是报错 哎 |