/*
人类Person
属性:姓名name,年龄age,性别gender
行为:学习study,睡觉sleep
*/
class Person_Test11 {
public static void main(String[] args) {
Person p1 = new Person();
p1.setName("董浩");
p1.setAge(25);
p1.setGender("男");
System.out.println(p1.getName()+"..."+p1.getAge()+"..."+p1.getGender());
p1.study();
p1.sleep();
}
}
class Person {
private String name;
private int age;
private String gender;
public Person() {}
public Person(String name,int age,String gender) {
this.name = name;
this.age = age;
this.gender = 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("睡觉");
}
}
|
|