一、如图中所说:按照深度遍历,其顺序为[D,B,A,object,C,A,object],重复类只保留最后一个,因此变为[D,B,C,A,object]。为什么顺序不是[D,B,A,object,C]?二、下面这个代码:classA(...
一、如图中所说:按照深度遍历,其顺序为 [D, B, A, object, C, A, object],重复类只保留最后一个,因此变为 [D, B, C, A, object]。为什么顺序不是[D,B,A,object,C]?二、下面这个代码:class A(): def go(self): print ("go A go!") def stop(self): print ("stop A stop!") def pause(self): raise Exception("Not Implemented")class B(A): def go(self): super(B, self).go() print ("go B go!")class C(A): def go(self): super(C, self).go() print ("go C go!") def stop(self): super(C, self).stop() print ("stop C stop!")class D(B,C): def go(self): super(D, self).go() print ("go D go!") def stop(self): super(D, self).stop() print ("stop D stop!") def pause(self): print ("wait D wait!") d = D()>>>go A go! go C go! go B go! go D go!为什么不是go A go!go B go!go C go!go D go!
代码重放下
class A():
def go(self):
print ("go A go!")
def stop(self):
print ("stop A stop!")
def pause(self):
raise Exception("Not Implemented")
class B(A):
def go(self):
super(B, self).go()
print ("go B go!")
class C(A):
def go(self):
super(C, self).go()
print ("go C go!")
def stop(self):
super(C, self).stop()
print ("stop C stop!")
class D(B,C):
def go(self):
super(D, self).go()
print ("go D go!")
def stop(self):
super(D, self).stop()
print ("stop D stop!")
def pause(self):
print ("wait D wait!")
展开