package pet;publicclassCatextendsPet{publicCat(){}publicCat(String name, int healthValues){super(name, healthValues);}publicvoidshowCat(){
System.out.println("昵称:"+ name);
System.out.println("健康值:"+ healthValues);}}
四、测试类Test
package pet;publicclassTest{publicstaticvoidmain(String[] args){
Pet p =newPet("牛牛",10);
p.showPet();
p.eat("草");
System.out.println();
Dog d =newDog("毛毛",10,"泰迪");
d.showDog();
d.eat("狗粮");
System.out.println();
Cat c =newCat("元宝",10);
c.showCat();
c.eat("猫粮");}}
pet一、题目二、父类Pet三、子类1、Dog类2、Cat类四、测试类Test五、效果展示一、题目二、父类Petpackage pet;public class Pet { protected String name; protected int healthValues; public Pet() { } public Pet(String name, int healthValues) { super(); this.name = name; this.healt