查询共创建了多少个对象
package 记录对象; import java.util.Scanner; class Number{ static int number=0; static void display() { ++number; System.out.println("目前共创建了"+number+"个对象"); } } public class duixiang { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String flag="y"; do{ Number a=new Number(); Number.display(); System.out.println("是否继续创建对象?请输入Y或者N"); flag=sc.next(); } while(flag.equals("y")||flag.equals("Y")); } }