多态

简介

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# coding:utf-8

# 重写父类方法,导致多态,同样的方法在不同的实例对象表现不用一样,龙生九子。

class Parent():
def talk(self):
print('小木的爸爸说了一句话')

class ChildOne(Parent):
def run(self):
print('小木在跑步')
def talk(self):
print(': 小木在说话')

if __name__ == '__main__':
xiaomu_brother = ChildOne()
xiaomu_brother.run()
xiaomu_brother.talk()