class Ticket implements Runnable
{
private int ticket=30;
public void run()
{
while(true)
{
if(ticket>0)
{
System.out.println(Thread.currentThread().getName()+"......"+ticket--);
//这里的Thread。为什么类继承Thread时,这里可以用Thread;但当类实现的是Runnable类的时候,这里可以用Thread,但不可以Runnable?????}
}}}
class Demo
{
public static void main(String[] args)
{
Ticket t=new Ticket();
Thread t1=new Thread(t);
Thread t2=new Thread(t);
Thread t3=new Thread(t);
t1.start();
t2.start();
t3.start();
}
}
|
|