@Setter
@Getter
@NoArgsConstructor
public class People {
// private People people;
private int id;
private String name;
private int age;
public static int count;//让所有对象共享一个count,而且要public,不然无法访问
public void Compare(@NonNull People people){
if(people.getAge()>=getAge()){
System.out.println(people.getName()+"年龄不小于"+getName());
}
else System.out.println(getName()+"年龄不小于"+people.getName());
}
public People(int id, String name, int age) {
count++;
this.id = id;
this.name = name;
this.age = age;
}
}
public static void main(String[] args) {
People people1 = new People(1,"张三",23);
People people2 = new People(2,"李四",18);
people1.Compare(people2);
System.out.println(People.count);
}
标签:People,int,people,private,id,次数,人类,public,属性
From: https://www.cnblogs.com/Liku-java/p/16802204.html