- 继承练习
class Animal:
def __init__(self, name, age):
self.name = name
self.age = age
def run(self, km):
print('每小时能跑{}km'.format(km))
def eat(self, food):
print('{}吃{}去吧'.format(self.name, food))
def show(self):
print('{}今年{}岁了'.format(self.name, self.age))
class Tiger(Animal):
def eat(self, food):
print('{}要吃{}'.format(self.name, food))
tiger1 = Tiger('辛巴', 2)
tiger1.show()
tiger1.eat('胡萝卜')
class Dog(Animal):
def __init__(self, name, age, color):
super(Dog, self).__init__(name, age)
self.color = color
def see_house(self):
print('柯基不会看家')
dog1 = Dog('奥利奥', 1, '黑白')
dog1.show()
dog1.see_house()
dog1.run(30)
dog1.eat('骨头')