您的位置:首页 > 其它

一个类的static变量在其所有实例化对象上是共享的

2009-03-24 12:32 260 查看
一个类的static变量在其所有实例化对象上是共享的
public class Test {
public static void main(String args[]){
staticValue a=new staticValue();
staticValue b=new staticValue();
a.add();
b.printA();
}
}
class staticValue {
static int a=1;
public void add(){
a++;
}
public void printA(){
System.out.println(a);
}
}


以上代码

最后输出是"2"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐