# -*-coding:utf-8 -*-
__author__ = ‘xiaojiaxin‘
__file_name__ = ‘多继承‘
#只有python和c++支持多继承
class grandf:
def a(self):
print("G1.a")
class father(grandf):
def a1(self):
print("F1.a")
class father2:
def a(self):
print("F2.a")
class son(father,father2): #(father)表示这个孩子的父亲就是father
pass
class son2(father2,father):
pass
obj=son()
obj.a()
# G1.a
obj2=son2()
obj2.a()
# F2.a
总结:
多继承:从左到右找,一条道走到黑,同一个根时,根最后执行,self始终是方法的调用者。
原文地址:http://blog.51cto.com/10777193/2096445