返回列表 發帖
  1. public class Ch100 {
  2.         private MyThread th;
  3.        
  4.         Ch100()
  5.         {
  6.                 th=new MyThread();
  7.                 th.start();
  8.                
  9.         }
  10.         public static void main(String[] args)
  11.         {
  12.                 new Ch100();
  13.         }
  14. }       

  15. class MyThread extends Thread
  16. {
  17.       public void run() {
  18.                 for(int i=5;i>=1;i--)
  19.                 {
  20.                         System.out.println(i+"秒");
  21.                         try{
  22.                                 Thread.sleep(1000);
  23.                         }catch(InterruptedException e) {}
  24.                 }
  25.            System.out.println("時間到");
  26.            System.out.println("執行緒名稱:"+Thread.currentThread().getName());
  27.         }
  28.        
  29. }
複製代碼

TOP

返回列表