public class ThreadTest
{
public static void main(String args[])
{
TestThread tt= new TestThread();
Thread t= new Thread(tt);
t.start();
while(true)
{
System.out.println("main thread is running");
}
}
}
class TestThread extends Thread //implements Runnable //这里实现接口和继承的效果都是一样的, 这个怎么区分,什么时候用接口实现 ,什么时候用继承呢?
{
public void run()
{
while(true)
{
System.out.println(Thread.currentThread().getName() +
" is running");
}
}
} |