这个程序是网上找到的,看不太懂。编译之后有几个错误,我不知道怎么改。
public class A 
{
    int i = 1;
    public A() 
    {
     Thread thread = new Thread();
      public void run() 
      {
        for(;;) 
        {
         A.this.run();
         try 
         {
           sleep(1000);
         } 
         catch(InterruptedException ie)
         {
         }
       }
     }
     thread.start();
  }
 
  public void run()
  {
   System.out.println("i = " + i);
   i++;
  }
  public static void main(String[] args) throws Exception 
  {
    new A();
  }
}

解决方案 »

  1.   

    应该是这样:
    public class A { int i = 1; public A() {
    Thread thread = new Thread() {
    public void run() {
    for (;;) {
    A.this.run();
    try {
    sleep(1000);
    } catch (InterruptedException ie) {
    }
    }
    }
    };
    thread.start();
    } public void run() {
    System.out.println("i   =   " + i);
    i++;
    } public static void main(String[] args) throws Exception {
    new A();
    }
    }
      

  2.   

     Thread   thread   =   new   Thread(); 这句中的 Thread 不和娄同名也可以吗?
      

  3.   

    Thread       thread       =       new       Thread();   这句中的   Thread   不和娄同名也可以吗? 
    回去看看java线程。
      

  4.   

    run方法要重写Thread类的
    这里要用到匿名内部类