//创建线程 class Xc3 extends Thread { public void run (){ System . out . println ( "当前线程的名称为" + Thread . currentThread (). getName ()); } } public class test29 { public static void main ( String [] args ){ Xc3 xc3 = new
class Xc3 extends Thread {
public void run(){
System.out.println("当前线程的名称为"+Thread.currentThread().getName());
}
}
public class test29{
public static void main(String[] args){
Xc3 xc3=new Xc3();
xc3.setName("线程1");//程序会自动调用run方法
xc3.start();
Xc3 xc4=new Xc3();
xc4.setName("线程2");//程序会自动调用run方法
xc4.start();
Xc3 xc5=new Xc3();
xc5.setName("线程3");//程序会自动调用run方法
xc5.start();
}
}
运行结果