根据如下需求,完成代码(按照标准格式写),然后在测试类中测试
人类Person
属性:姓名name,年龄age,性别gender
行为:学习study,睡觉sleep
class Person {
public static void main(String[] args) {
Personl p =new Personl();
p.setName("张敏");
p.setAge(20);
p.setGender("女士");
System.out.println(p.getName()+" "+p.getAge()+" "+p.getGender() );
p.study();
p.sleep();
}
}
class Personl{
private String name;
private int age;
private String gender;
public void setName(String name){
this.name =name;
}
public String getName(){
return name;
}
public void setAge(int age)
{
this.age =age;
}
public int getAge()
{
return age;
}
public void setGender(String gender)
{
this.gender =gender;
}
public String getGender()
{
return gender;
}
public void study(){
System.out.println("学习");
}
public void sleep(){
System.out.println("睡觉");
}
} |
|