java编程中,对静态变量的修改会影响到所有对象,静态成员的一个例子:
package Test;
public class StaticTester {
public static void main(String[] args){
StaticTest.y+=1;
StaticTest t1 = new StaticTest();
StaticTest t2 = new StaticTest();
t1.x+=1;
t1.y+=1;
t2.x+=2;
t2.y+=2;
System.out.println("T1:x= " + t1.x +",y = " + t1.y);
System.out.println("T1:x= " + t2.x +",y = " + t2.y);
}
}
class StaticTest{
public int x=1;
public static int y = 1;
}
输出如图: