- public class Ch121 extends Thread
- {
- MyThread th;
- Ch121()
- {
- th=new MyThread();
- th.start();
- }
- public static void main(String[] args)
- {
- new Ch121();
- }
- }
複製代碼- class MyThread extends Thread{
-
- public void run() {
- for(int i=5; i>=1; i--)
- {
- System.out.println(i+"秒");
- try
- {
- Thread.sleep(1000);
- } catch (InterruptedException e) {}
-
- }
- System.out.println("時間到!");
- System.out.println("執行緒名稱: "+Thread.currentThread().getName());
- }
-
- }
複製代碼 |