目标:人可以喂任何一种动物
class Animal(object):
def __init__(self,name):
self.name = name
def eat(self):
print(self.name + "吃")
class Cat(Animal):
def __init__(self, name):
# self.name = name
super().__init__(name)
# def eat(self):
# print(self.name + "吃")
class Mouse(Animal):
def __init__(self, name):
# self.name = name
super().__init__(name)
# def eat(self):
# print(self.name + "吃")
class Person(object):
# def feedCat(self, cat):
# print("给你食物")
# cat.eat()
# def feedMouse(self, mouse):
# print("给你食物")
# mouse.eat()
def feedAnimal(self, ani):
print("给你食物")
ani.eat()
def main():
tom = Cat("tom")
tom.eat()
jer = Mouse("jer")
jer.eat()
per = Person()
# per.feedCat(tom)
# per.feedMouse(jer)
per.feedAnimal(tom)
per.feedAnimal(jer)
if __name__ == '__main__':
main()
网友评论