- package cn.it_05;
- //创建继承线程.
- class Test extends Thread //创建线程继承Thread
- {
- //private String name;
- Test(String name) //构造方法,一个参数
- {
- //this.name = name;
- [color=Red]super(name); [/color] //[color=Blue]为什么要是super呢?[/color]
- }
- public void run() //定义行为
- {
- for(int x = 0;x < 60;x++)
- {
- System.out.println((Thread.currentThread()==this)+"..."+this.getName()+"run..."+x);
- }
- }
- }
- public class ThreadTest {
- public static void main(String[] args) {
- Test t1 = new Test("11-----"); //创建一个线程
- Test t2 = new Test("22222+++"); //创建一个线程.
- t1.start(); //运行线程1
- t2.start(); //运行线程2
-
- for(int x =0;x <60;x++)
- {
- System.out.println("main......"+x); //主线程,,,
- }
- }
- }
复制代码 |
|