class TTest extends Thread{
TTest(String name){
super(name); //自定义线程名称
}
public void run(){
for (int i = 0; i < 400; i++) {
System.out.println("线程 :"+this.getName()+"运行打印:"+i);
}
}
}
public class ThreadTest {
public static void main(String[] args) {
TTest t=new TTest("one:");
t.start();
TTest t2=new TTest("two:");
t2.start();
new Thread(){
public void run(){
for (int i = 0; i < 200; i++) {
System.out.println("匿名内部类型线程:"+Thread.currentThread().getName());
}
}
}.start();
for (int i = 0; i < 300; i++) {
System.out.println(Thread.currentThread().getName()+"运行打印:"+i);
}
}
}