定义一个有关人的Person类,内含属性: String name、int age、boolean gender、int id,所有的变量必须为私有(private)。
时间: 2024-05-13 19:13:42 浏览: 96
关于Person的类例子
好的,这是一个关于Java编程的问题。下面是Person类的定义:
```
public class Person {
private String name;
private int age;
private boolean gender;
private int id;
public Person(String name, int age, boolean gender, int id) {
this.name = name;
this.age = age;
this.gender = gender;
this.id = id;
}
//Getter and Setter methods for all private variables
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 boolean isGender() {
return gender;
}
public void setGender(boolean gender) {
this.gender = gender;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
```
希望可以帮到你。
阅读全文