司风0
以继承的方式写:线程1:class Ther1 extends Thread{
@Override
public void run() {
System.out.println("线程1");
}
}线程2
class Ther2 extends Thread{
@Override
public void run() {
System.out.println("线程2");
}
}开启线程public class Code {
//以继承的方式
public static void main(String[] args){
Ther1 t1=new Ther1();
Ther2 t2=new Ther2();
t1.start();//开启线程1
t2.start();//开启线程2
}
}运行结果线程1
线程2