提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
Java静态成员变量示例
/** 来自 n o w j a v a . c o m**/ public class Main { public static void main(String[] args) { ObjectCounter object1 = new ObjectCounter(); System.out.println(object1.getNumberOfObjects()); ObjectCounter object2 = new ObjectCounter(); System.out.println(object2.getNumberOfObjects()); } } class ObjectCounter{//来自 n o w j a v a . c o m - 时 代 Java static int counter=0; public ObjectCounter(){ counter++;