目录
题目需求
已知有如下Animal抽象类,请编写其子类Dog类与Cat类,另外再编写一个生产动物的Factory工厂类,具体要求如下。
已有的Animal抽象类定义:
abstract class Animal{ private String name; //名字 private int age; //年龄 public abstract void info(); //返回动物信息 public abstract void speak(); //动物叫 public Animal(String name, int age) { this.name = name; this.age = age; } 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; } }
需要你编写的Dog子类:
增加violence(凶猛程度)属性(int型),重写info和speak方法
info方法输出Dog的name、age和violence属性,输出格式样例为:该狗的名字是Mike,年龄是2岁,凶猛程度是78度 (注意:输出结果中没有空格,逗号为英文标点符号)
speak方法输出Dog 的叫声,输出格式样例为:旺旺
需要你编写的Cat子类:
增加mousingAbility(捕鼠能力)属性(int型),重写info和speak方法
info方法输出Cat的name、age和mousingAbility属性,输出格式样例为:该猫的名字是Kitty,年龄是4岁,捕鼠能力是88分 (注意:输出结果中没有空格,逗号为英文标点符号)
speak方法输出Cat 的叫声,输出格式样例为:喵喵
需要你编写的