public class T1 {
public static void main(String[] args) {
MyThread mt1 = new MyThread(0);
MyThread mt2 = new MyThread(2);
MyThread2 mt3 = new MyThread2(2);
MyThread2 mt4 = new MyThread2(2);
mt1.start();
mt2.start();
mt3.start();
mt4.start();
}
}
//减操作
class MyThread extends Thread{
private int i;
public MyThread(int i) {
this.i=i;
}
public void run() {
i--;
System.out.println("减操作-->"+i);
}
}
//加操作
class MyThread2 extends Thread{
private int i;
public MyThread2(int i) {
this.i=i;
}
public void run() {
i++;
System.out.println("加操作-->"+i);
}
}
运行结果: