首页 > 其他 > 详细

多重继承

时间:2019-07-31 20:43:47      阅读:106      评论:0      收藏:0      [点我收藏+]
 1 #  太爷爷 -> 爷爷 -> 爸爸 -> 儿子
 2 # 单继承 : 一个父类对应一个子类
 3 # 多重继承 : 子类有父类,父类有父类 。。。。
 4 class YeYe():
 5     def __init__(self, house):
 6         self.house = house
 7         self.__wan = "古董"
 8     def merry(self):
 9         print("爷爷和奶奶结婚了")
10 class Father(YeYe):
11     def __init__(self, house, car):
12         YeYe.__init__(self, house)
13         self.car = car
14     def merry(self):
15         # YeYe.merry(self)
16         print("爸爸和妈妈结婚了")
17     def work(self):
18         print("爸爸上班")
19 class Son(Father):
20     def __init__(self, house, car, computer):
21         Father.__init__(self, house, car)
22         self.computer = computer
23     def merry(self):
24         Father.merry(self)
25         print("就找女朋友,不结婚")
26 
27 son1 = Son("大房子", "二手奥拓", "dell")
28 print(son1.house, son1.car, son1.computer)
29 son1.merry()

 

多重继承

原文:https://www.cnblogs.com/BKY88888888/p/11278706.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!