static属于class类的,不是属于某个对象的
2018-01-20 23:21
155 查看
staic是属于class类的,不是属于某个此类所创建的某个对象引用的。所以当你在debug时会发现,在Variables栏中并不会找到当前引用对象中static所修饰的变量。
测试代码块
package yu.bai.array; public class BerylliumSphere { private static long counter; private final long id = counter++; public String toString(){ return "Sphere" + id; } public static long getCounter() { return counter; } public long getId() { return id; } package yu.bai.array; public class ContainerComparison { public static void main(String[] args) { BerylliumSphere[] spheres = new BerylliumSphere[10]; for (int i = 0; i < 5; i++) { spheres[i] = new BerylliumSphere(); System.out.println(spheres[i].getCounter() + "," + spheres[i].getId()); } } } 当执行spheres[0] = new BerylliumSphere()时,debug运行的Variables栏中只有类BerylliumSphere的id属性,并没有显示counter属性。
相关文章推荐
- const对象默认是static的,而不是extern的
- 面向对象_补充_封装_成员与局部变量_static关键字_Math随机数
- 来段代码提提神-那些无法回避的知识点之map以对象为key,static的加载顺序。
- 面向对象知识点之statickeyword的使用
- js 解决“options为空或不是对象”
- 局部对象,static局部对象,static全局对象
- [bxd学习java基本点]9.ArrayList存对象例子,其除重复及删除,要使用地址,而不是eqauls
- 【06】面对对象2_static关键字,单例设计模式
- Extjs window弹出框 第二次打开时会报:【'addCls' 为空或不是对象】错误
- DOM对象本身也是一个js对象,所以严格来说,并不是操作这个对象慢,而是说操作了这个对象后,会触发一些浏览器行为(转)
- C++-const_cast只能用于指针和引用,对象的const到非const可以用static_cast
- 1. PHP是一门面向对象语言,但不是基于OOPS
- Core Foundation 对象不属于ARC的管辖范围
- jquery null为空或不是对象
- 实例化Class类对象几种方式
- php检测一个给定的对象是否属于(…
- TObjectList.Assign 复制的是指针不是对象
- jQuery UI DatePicker“length为空或不是对象”错误的解决方法
- Java中的Class类和Class对象
- jQuery UI Datepicker“’length’为空或不是对象”错误的解决方