class Demo extends Thread
{
//private String name;
Demo(String name)
{
//this.name=e;
super(name);
System.out.println(this.name);
}
public void run()
{
//for(int x=0;x<=1;x++)
//System.out.println(this.getName()+"run.."+x);
}
}
class ThreadDemo
{
public static void main(String [] args)
{
//for(int x=0;x<=90;x++)
// System.out.println("Demo run"+x);
Demo d1=new Demo("one..............");
Demo d2=new Demo("two.....................");
d1.start(); //开启线程并执行线程的run方法
//d.run(); 仅仅是对象调用方法 线程创建了,但并未执行
d2.start();
//for(int x=0;x<=1;x++)
//System.out.println("Demo run"+x);
}
} |
|