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这两个代码块有什么显着差异吗?
慕妹3242003
智慧大石
BIG阳
随时随地看视频慕课网APP
相关分类