用JAVA编译一道题~~~~~~~

来源:百度知道 编辑:UC知道 时间:2024/05/22 10:26:10
定义一个人类,包含姓名,性别,年龄,等信息
所有变量必须私有,其它类只能通过该类的方法获取或修改。实例化一个人类,并通过该方法修改实例化的人的信息。
作业~~~~~谢谢了~~~~~~~~~

package IO;

public class Person {

private String name;
private String sex;
private int age;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the sex
*/
public String getSex() {
return sex;
}
/**
* @param sex the sex to set
*/
public void setSex(String sex) {
this.sex = sex;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
public static void main(String[] args){
Person p = new Person();
p.setName("刘德华");
p.setSex("男");
p.setAge(18);