一起找bug

时间:2023-03-09 06:44:44
一起找bug

帮同学找的一个bug,错误代码如下:

 package dai_test;
public class Test1 { public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread myThread = new MyThread();
myThread.setName("dai");
myThread.start();
}
class MyThread extends Thread{
public void run() {
super.run();
for(int i =0;i<10;i++){
System.out.println( "Main.run()"+i+Thread.currentThread().getName() );
}
}
}
}

错误信息为第6行:No enclosing instance of type Test1 is accessible. Must qualify the allocation with an enclosing instance of type Test1 (e.g. x.new
 A() where x is an instance of Test1).

错误原因:将class MyThread写到了Class Text1里面。。。