package com.swift; //使用无参构造方法自动生成对象,序号不断自增 public class Person { private static int count; //如果在定义类时,使用的是静态的属性,则得到的结果是不同的。count生命周期长,与类相同 public int id; public String name; public int age; public String city; public Person() { super(); count++; this.id=count; this.name="NoName"+count; this.age=20; this.city="蜀国"; System.out.println("生产了 "+count+" 个实例化对象");//调用空参构造方法时输出 } public Person(int id ,String name,int age,String city) { this.id=id; this.name=name; this.age=age; this.city=city; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getInfo() { return "The Person is id=" + id + ", name=" + name + ", age=" + age + ", city=" + city ; } }