【发布时间】:2010-06-12 04:32:14
【问题描述】:
请解释以下代码的输出:
如果我调用th1.run(),输出是:
EXTENDS RUN>>
RUNNABLE RUN>>
如果我调用th1.start(),输出是:
RUNNABLE RUN>>
EXTENDS RUN>>
为什么会出现这种不一致?请解释一下。
class ThreadExample extends Thread{
public void run() {
System.out.println("EXTENDS RUN>>");
}
}
class ThreadExampleRunnable implements Runnable {
public void run() {
System.out.println("RUNNABLE RUN>>");
}
}
class ThreadExampleMain{
public static void main(String[] args) {
ThreadExample th1 = new ThreadExample();
//th1.start();
th1.run();
ThreadExampleRunnable th2 = new ThreadExampleRunnable();
th2.run();
}
}
【问题讨论】:
标签: java multithreading