admin管理员组文章数量:1130349
文章目录
- 一、父类--Pet
- 二、子类--DogLady
- 三.子类--CatLady
- 四.主人类--Master
- 五.功能测试类--Test
-
- 效果截图
- 总结
一、父类–Pet
示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建
的。
public class Pet {
private String name;
private int age;
private int health;
public Pet(int health) {
this.health = health;
}
public Pet() {
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
if (this.health>=100){
this.health=100;
System.out.println("人..人家真的吃不下了");
}
this.health = health;
}
public void eat(String food){
System.out.println("宠物吃"+food);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
二、子类–DogLady
代码如下(示例):
public class DogLady extends Pet {
private int love;
public DogLady(int health) {
super(health);
}
public DogLady() {
}
//宠物玩耍
public void play(){
System.out文章目录
- 一、父类--Pet
- 二、子类--DogLady
- 三.子类--CatLady
- 四.主人类--Master
- 五.功能测试类--Test
-
- 效果截图
- 总结
一、父类–Pet
示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建
的。
public class Pet {
private String name;
private int age;
private int health;
public Pet(int health) {
this.health = health;
}
public Pet() {
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
if (this.health>=100){
this.health=100;
System.out.println("人..人家真的吃不下了");
}
this.health = health;
}
public void eat(String food){
System.out.println("宠物吃"+food);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
二、子类–DogLady
代码如下(示例):
public class DogLady extends Pet {
private int love;
public DogLady(int health) {
super(health);
}
public DogLady() {
}
//宠物玩耍
public void play(){
System.out版权声明:本文标题:java 电子宠物系统 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1760286173a2851503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论