Java定义一个人类,属性:姓名,性别,身份证,年龄
时间: 2023-05-16 21:06:25 浏览: 764
可以使用以下代码定义一个人类:
public class Person {
private String name;
private String gender;
private String idNumber;
private int age;
public Person(String name, String gender, String idNumber, int age) {
this.name = name;
this.gender = gender;
this.idNumber = idNumber;
this.age = age;
}
// Getters and setters for the attributes
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getIdNumber() {
return idNumber;
}
public void setIdNumber(String idNumber) {
this.idNumber = idNumber;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
阅读全文