class S implements Runnable {
public S() {
System.out.println("Runnable starts!");
}
public void run() {
for(int i=0;i<3;i++) {
System.out.println("Runnable");
}
}
}
public class A extends Thread {
public A() {
System.out.println("Thread Starts!");
}
public void run() {
for(int i=0;i<3;i++) {
System.out.println("Thread");
}
}
public static void main(String[] args) {
new Thread(new S()).start();
new A().start();
}
}
输出结果
Runnable starts!
Thread Starts!
Runnable
Runnable
Runnable
Thread
Thread
Thread
为什么不是
Runnable starts!
Thread Starts!
Runnable
Thread
Runnable
Thread
Runnable
Thread |
|