Java中的“实现Runnable”与“扩展线程”
从我在Java中使用线程的时间开始,我发现了这两种编写线程的方法:
用implements Runnable
:
public class MyRunnable implements Runnable { public void run() { //Code }}//Started with a "new Thread(new MyRunnable()).start()" call
或者,用extends Thread
:
public class MyThread extends Thread { public MyThread() { super("MyThread"); } public void run() { //Code }}//Started with a "new MyThread().start()" call
这两个代码块有什么显着差异吗?
智慧大石
BIG阳
相关分类