class Dog(object):
def __init__(self, name):
self.name = name
def game(self):
print("%s 砰砰跳跳的玩耍。。。" % self.name)
class XiaoTianDog(Dog):
def game(self):
print("%s 飞到天上去玩耍。。。" % self.name)
class Person(classmethod):
def __init__(self, name):
self.name = name
def game_with_dog(self, dog):
print("%s和%s快乐的玩耍。。。" %(self.name, dog.name))
# 让狗玩耍
dog.game()
# 1. 创建对象
# wangcai = Dog("旺财")
wangcai = XiaoTianDog("飞天旺财")
# 2. 创建一个小明对象
xiaoming = Person("小明")
# 3. 让小明调用和狗玩耍的方法
xiaoming.game_with_dog(wangcai)
多态
最新推荐文章于 2022-04-28 22:36:36 发布