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