下面的程式码A要先extends Thread
才能做:TimerThread newThread = new TimerThread();
为什么程式码B没有extends Thread之类的动作
就能使用Thread:Thread newThread = new Thread(test)
为什么呢
thanks
程式码A:
class TimerThread extends Thread { //执行绪
public void run() { // 执行绪要执行的内容
...
}
}
public class TestThread {
public static void main(String[] argv) {
TimerThread newThread = new TimerThread();
newThread.start(); // 启动执行绪
...
}
}
程式码B:
class TimerThread implements Runnable {//以Runnable接口建立执行绪
public void run() { // 执行绪要执行的内容
...
}
}
public class TestRunnable {
public static void main(String[] argv) {
TimerThread test = new TimerThread();
Thread newThread = new Thread(test)
newThread.start(); // 启动执行绪
...
}
}