package 创建对象数目; import java.nio.charset.MalformedInputException; public class Sum { private static int m=0; public Sum() { m++; } public static int getsum() { return m; } public static void main(String[] args) { Sum a1=new Sum(); Sum a2=new Sum(); Sum a3=new Sum(); System.out.println("创建对象数目:"+Sum.getsum()); } }