20、多继承的实现
1、示例
------------------------------
class Father(object):
def __init__(self, money):
self.money = money
def play(self):
print("play")
def func(self):
print("func1")
----------------------------------
class Mother(object):
def __init__(self, faceValue):
self.faceValue = faceValue
def eat(self):
print("eat")
def func(self):
print("func2")
------------------------------
from Father import Father
from Mother import Mother
class Child(Father, Mother):
def __init__(self, money, faceValue, height):
Father.__init__(self, money)
Mother.__init__(self, faceValue)
self.height = height
---------------------------------
from Child import Child
def main():
c = Child(300, 100, 11111111)
print(c.money, c.faceValue)
c.play()
c.eat()
#注意:父类中方法名相同,默认调用的是在括号中排在前面的父类中的方法
c.func()
print(c.height)
if __name__ == "__main__":
main()
浙公网安备 33010602011771号