先看以下两个代码:
package thread;
public class StartThread implements Runnable{
public static void main(String[] args) {
StartThread s=new StartThread();
Thread t=new Thread(s);
t.start();
}
public void start(){
System.out.println("start...");
}
public void run() {
System.out.println("run....");
}
}
输出:run
package thread;
public class TT extends Thread {
public static void main(String[] args) {
TT t = new TT();
t.start();
}
public void start() {
System.out.println("start");
}
public void run() {
System.out.println("run");
}
}
输出:start
原因:start方法在二中被重写