【发布时间】:2019-02-28 10:30:53
【问题描述】:
在类继承方面,我不是最强的支柱,所以这是我相当愚蠢的问题。按照下面的代码,我会在逻辑上假设在“super”调用之后,指针到达 self.example(),这又会引用同一类中的“example”方法,并且将打印值 20。
class A(object):
def __init__():
self.example()
def example(self):
print(20)
class B(A):
def __init__():
super().__init__()
def example(self):
print(10)
x = B()
结果:10
显然不是这样,而是打印了 10。有人可以对类继承的神秘世界有所了解。
【问题讨论】:
标签: python-3.x inheritance subclassing