person是父类,内置了paly和dance的方法,但是OldMan和YouMan这两个子类不想要去调用父类Person的dance方法,需要执行自己的同名dance方法,这个就被称作是多态
class Person:
def dance(self):
print("我是大侠,就要舞剑")
def play(self):
print("普通的disc")
self.dance()
print("普通的摇摆")
class OldMan(Person):
def dance(self):
print("我是老年人,喜欢广播体操")
class YouMan(Person):
def dance(self):
print("我是年轻人就喜欢跑酷")
daxia = Person()
daxia.play()
laowang = OldMan()
laowang.play()
xiaozhang = YouMan()
xiaozhang.play()