class Test{
public void main(String[] args){
A testA=new A(); //这里会出现问题
new Thread(new Runnable(){
public void run(){
testA.printout();
}
}).start();
System.out.println("aaaaaa");
}
class A{
public void printout(){
System.out.println("aaaaaa");
}
}
}
// 修改之后的代码如下:
class Test{
public void main(String[] args){
new Test().init();
System.out.println("aaaaaa");
}
public void init(){
A testA=new TestA();
new Thread(new Runnable(){
public void run(){
testA.printout();
}
}).start();
}
class A{
public void printout(){
System.out.println("aaaaaa");
}
}
}