源代码:
package 类的统计; class Num{ private static int n; public Num() { n++; } public static int get() { return n; } } public class Tongji { public static void main(String[ ]args) { Num n1=new Num(); Num n2=new Num(); System.out.println("创建对象的个数为:"+Num.get()); } }