1.private加密
private String name;
private String type;
private String sex;
private int health;
private int love;
2.set,get用法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
if (health<0||health>100){
System.out.println("你输入的健康值有误,改为默认值");
this.health=60;
return;
}
this.health = health;
}
public int getLove() {
return love;
}
public void setLove(int love) {
if (love<0||love>100){
System.out.println("你输入的亲密度有误,改为默认值");
this.love=60;
}else this.love = love;
}
3.引用属性
public void introduce(){
System.out.println("宠物的自白:");
System.out.println("我的名字叫"+getName()+",健康值是"+getHealth()+",和主人的亲密度是"+getLove()+",我的性别是"+getSex());
}
4.包
5.类成员修饰
6.static静态修饰符