想问一下线程继承Thread类和实现Runnable接口用法有什么不一样,什么时候用什么?
public class Test {
public static void main(String[] args) {
new TestThread1().start();
TestThread2 tt = new TestThread2();
new Thread(tt).start();
}
}
class TestThread1 extends Thread{
public void run(){
for(int i = 0;i<=10;i++)
System.out.println("继承Thread");
}
}
class TestThread2 implements Runnable{
public void run(){
for(int i = 0;i<=10;i++)
System.out.println("实现Runnable接口");
}
}