<分区>
Possible Duplicate:
java thread - run() and start() methods
我制作了一个使用线程的程序---
public class ThreadTest{
public static void main(String[] args){
MyThread newthread=new MyThread();
Thread t=new Thread(newthread);
t.start();
for(int x=0;x<10; x++){
System.out.println("Main"+x)
}
}
}
class MyThread implements Runnable{
public void run(){
for(int x=0; x<10; x++){
System.out.println("Thread"+x);
}
}
}
现在我的问题是......为什么我们使用“Thread”类并创建它的对象并在它的构造函数中传递“MyThread”调用?我们不能通过创建它的对象并调用 run 方法来调用“MyThread”对象的 run 方法吗?
(即 MyThread newthread=new MyThread(); 然后是 newthread.run();
)
创建踏板对象并在其中传递 MyThread 类的原因是什么?