新式类与经典类
class A():
def __init__(self):
print 'my name is GF'
def test(self):
print 'this is ====A====='
class B(A):
def __init__(self):
print 'my name is BFather'
class C(A):
def __init__(self):
print 'my name is Cfather'
def test(self):
print 'this is ======C======'
class D(B,C):
def __init__(self):
print 'my name is D'
t1 =D()
t1.test()
执行效果:
my name is D
this is ======A======
#继承关系,先找B,如果B没有则找A.(深度优先)
class A(object):
def __init__(self):
print 'my name is GF'
def test(self):
print 'this is ====A====='
class B(A):
def __init__(self):
print 'my name is BFather'
class C(A):
def __init__(self):
print 'my name is Cfather'
def test(self):
print 'this is ======C======'
class D(B,C):
def __init__(self):
print 'my name is D'
t1 =D()
t1.test()
执行结果
my name is D
this is ======C======
#继承关系,先找B,如果B没有则找C(广度优先)

浙公网安备 33010602011771号