返回列表 發帖
  1. public class Ch123 {
  2.     private MyThread th;
  3.     Ch123()
  4.     {
  5.             th=new MyThread();
  6.             th.start();
  7.     }
  8.         public static void main(String[] args) {
  9.             new Ch123();
  10.         }
  11. }
  12. class MyThread extends Thread
  13. {
  14.         public void run()
  15.         {
  16.                 for(int i=5;i>=1;i--)
  17.         {
  18.                 System.out.println(i+"秒");
  19.                 try {
  20.                         Thread.sleep(1000);
  21.                 } catch (InterruptedException e) {}        
  22.         }
  23.         System.out.println("時間到");
  24.         System.out.println("執行緒名稱:"+Thread.currentThread().getName());
  25.         }
  26. }
複製代碼

TOP

返回列表