返回列表 發帖
  1. public class Ch121 extends Thread
  2. {
  3.         MyThread th;
  4.         Ch121()
  5.         {
  6.                 th=new MyThread();
  7.                 th.start();
  8.         }

  9.         public static void main(String[] args)
  10.         {
  11.                 new Ch121();
  12.         }

  13. }
複製代碼
  1. class MyThread extends Thread{
  2.        
  3.         public void run() {
  4.                 for(int i=5; i>=1; i--)
  5.                 {
  6.                         System.out.println(i+"秒");
  7.                         try
  8.                         {
  9.                                 Thread.sleep(1000);
  10.                         } catch (InterruptedException e) {}
  11.                        
  12.                 }
  13.                 System.out.println("時間到!");
  14.                 System.out.println("執行緒名稱: "+Thread.currentThread().getName());
  15.         }
  16.    
  17. }
複製代碼

TOP

返回列表