这段字符串描述了一个基类animal,该类有数据成员年龄age、颜色color和种类type。成员函数show用于显示成员值。从类animal派生出类cat,该类有数据成员身高height,成员函数show用于显示成员值。
时间: 2024-02-15 17:02:23 浏览: 25
好的,根据你的要求,我可以写出以下的 Python 代码:
```python
class Animal:
def __init__(self, age, color, type):
self.age = age
self.color = color
self.type = type
def show(self):
print("Age:", self.age)
print("Color:", self.color)
print("Type:", self.type)
class Cat(Animal):
def __init__(self, age, color, type, height):
super().__init__(age, color, type)
self.height = height
def show(self):
super().show()
print("Height:", self.height)
```
以上代码定义了一个名为 `Animal` 的基类,其中有三个数据成员:年龄、颜色和种类。这个类还有一个名为 `show` 的成员函数,用于显示成员值。然后,这个类被派生出了一个名为 `Cat` 的子类,这个子类添加了一个名为 `height` 的数据成员。同时,这个类也重新定义了 `show` 方法,以便在显示基类的成员值之后,也能显示出猫的身高。