您的位置:首页 > 其它

创建线程的第一种方式:继承Thread…

2013-12-02 19:24 357 查看
步骤:

1、定义类继承Thread

2、复写Thread类中的run方法

3、调用线程的start方法

      
作用:启动线程,调用run方法

 

class Demo extends Thread

{

 public void run()

 {

  for(int x = 0; x<60;
x++)

  System.out.println("demo
run!!!!!!!"+x);

 }

}

class  ThreadDemo

{

 public static void main(String[] args)

 {

  //System.out.println("Hello
World!");

  Demo d = new Demo();

  d.start();

  for(int x = 0; x<60;
x++)

   System.out.println("hello
world!!!!!!!"+x);

 }

}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: