定义小猫类Cat继承Pet类,除了重写方法外还要添加一个特有的catchMouse()方法,输出内容为“小猫会抓老鼠”。
时间: 2024-05-14 22:14:53 浏览: 110
```
class Cat(Pet):
def __init__(self, name, age, gender):
super().__init__(name, age, gender)
def voice(self):
print(f"{self.name}喵喵叫")
def catchMouse(self):
print("小猫会抓老鼠")
```
相关问题
java定义小猫类Cat继承Pet类,除了重写方法外还要添加一个特有的catchMouse()方法,输出内容为“小猫会抓老鼠”。
```
public class Cat extends Pet {
// 添加特有的方法
public void catchMouse() {
System.out.println("小猫会抓老鼠");
}
// 重写父类方法
@Override
public void play() {
System.out.println("小猫喜欢玩毛线球");
}
}
```
阅读全文
相关推荐












