代码整体左移快捷键:shift+table
代码整体右移快捷键:table
import java.sql.SQLOutput;
/*
* 宠物狗狗类
* */
public class Dog {
//昵称,默认值是“无名氏”
private String name="无名氏";
//健康值,默认值是100,健康值在0-100之间,小于60为不健康
private int health=100;
//亲密度
private int love=0;
//品种
private String strain="聪明的拉布拉多犬";
//2.添加属性的setter/getter方法(方法公开),并加入属性控制语句
//setter:1.属性赋值。2.属性的操作(正确判断等)
public void setHealth(int health){
if(health<0||health>100){
System.out.println("请输入0-100的值!");
this.health=60;
return;
}
this.health=health;
}
//getter:属性取值
public int getHealth(){
return this.health;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public int getLove() {
return this.love;
}
public void setLove(int love) {
if(love<0||love>100){
相关知识
dnf宠物装备怎么封装
访问者模式==封装??
FLV封装格式介绍及解析
毛毛宠记忆城堡:毛毛宠宠物殡葬师的自白
9月11日宠物胶囊出售 可封装节日宠物
学会继承、多态、封装(1)——Java实现宠物店(领养宠物)
宠物练习
练习
反应速度的练习方法
宠物狗的“社会化”练习
网址: 封装的练习(宠物自白) https://m.mcbbbk.com/newsview318577.html
上一篇: 原创 成 |
下一篇: 支付宝关爱宠物健康怎么完成任务的 |