一个不解的问题

jackyyp 2003-10-20 11:09:40
public class test {
public static void main(String args[]){
MyThread myThread = new MyThread();
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
myThread.start();
thread.start();
}
}
class MyThread extends Thread{
public void run(){
System.out.println("MyThread: run()");
}
public void start(){
System.out.println("MyThread: start()");
}
}
class MyRunnable implements Runnable{
public void run(){
System.out.println("MyRunnable: run()");
}
public void start(){
System.out.println("MyRunnable: start()");
}
}
为什么输出只是MyThread: start() MyRunnable: run()
而不输出MyThread: run()呢?
...全文
23 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
duoshanx 2003-10-20
  • 打赏
  • 举报
回复
up!
loveyousomuch 2003-10-20
  • 打赏
  • 举报
回复
Thread的start()(继承Runnable)方法是自动调用run()方法的,
而MyThread,MyRunnable类重写了start()方法,
而其中未调用run()方法!!
LoveRose 2003-10-20
  • 打赏
  • 举报
回复
class MyThread extends Thread 继承后覆盖了Thread的start方法
所以调用start方法并不会自动启动线程的run方法。
当然输出只是MyThread: start()

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧