静态变量是可以修改的,很少有人这么干
最好的例子莫过于多线程卖火车票:
public class TicketSeller {
public static void main(String[] args) {
new Ticket().start();
new Ticket().start();
new Ticket().start();
}
}
class Ticket extends Thread{
private static int ticket = 100;
@Override
public void run() {
while (ticket > 0) {
System.out.println(this.getName() + " " + ticket--);
}
}
}