package com.leiheduixiang.a;
public class Dog {
private int health=100;
public int getHealth() {
return health;
}
public void setHealth(int health) {
if(health>100 || health<0) {
this.health=60;
}else {
this.health = health;
}
}
}
package com.leiheduixiang.a;
public class Test {
public static void main(String[] args) {
Dog dog=new Dog();
dog.setHealth(1000);
System.out.println(dog.getHealth());
}
}
package com.leiheduixiang.a;
public class penguin {
public static final String SEX_MALE="Q仔";
public static final String SEX_FEMALE="Q妹";
private String sex="未知";
public String getSEX() {
return sex;
}
public void setSEX(String sex) {
this.sex=sex;
}
}
package com.leiheduixiang.a;
public class Test2 {
public static void main(String[] args) {
penguin pg=new penguin();
pg.setSEX(penguin.SEX_FEMALE);
System.out.println("企鹅的性别是:"+pg.getSEX());
}
}