接上一篇,继续看看java线程问题。当然,下面的程序或者说用法很傻。
public class ThreadTest2
{
public static void main(String args[])
{
System.out.println("start");
Thread1 a = new Thread1();
a.start();
System.out.println("continue");
Thread2 b = new Thread2();
Thread t = new Thread(b);
t.start();
System.out.println("end");
}
}
//可以没有run()方法
class Thread1 extends Thread
{
}
//必须有run()方法,否则编译错误
class Thread2 implements Runnable
{
public void run()
{
}
}
输出为:
start
continue
end