静态变量复习
静态变量储存在内存数据区,如果非私有,不需new 就能职位访问
------------
class St{
public static int sid;
int id;
St(int a){
this.id=a;
sid++;
}
}
class Test{
public static void main(String[] args){
St.sid=100;
St t1 = new St(2);
St t2 = new St(4);
System.out.println(t1.sid+","+t2.sid);
}
}
------
运行结果:
102,102