这样写:
class A extends Thread
{
public void run()
{
          wile(true){
         output();
         try{
         sleep(3000);

}catch(InterruptedException ie){System.out.println(ie.getMessage());}
          }
public synchronized void output()
{
System.out.println("123456789");
}
}
public class B1 extends A
{

public static void main(String[] args) 
{
B1 b=new B1();
b1.start();
}
}
一般不是多继承就没必要实现那个runnable接口,直接继承thread类

解决方案 »

  1.   

    就單純你這個例子來說,public class B1 extends A
    是多於的!public class B1 
    {

    public static void main(String[] args) 
    {
    B1 bb=new B1();
    while(true)
    {
    try{Thread.sleep(3000);}
    catch(Exception e){}
    bb.output();
    }
    }
    public  void output()
    {
    System.out.println("1");
    }
    }
    有很多寫法,你還可以用Timer/TimerMask最好是用runnable接口