类的继承小问题(1):
带有封装私有化属性的继承类:
class Foo:
def __init__(self):
self.__func()
def __func(self): #私有化方法,这时self是指Foo -》_Foo__func()
print('in foo')
class Son(Foo):
def __func(self):
print('in son')
Son()
结果:
in foo
不带封装的继承类:
class Foo:
def __init__(self):
self.func() #self指的是son——》son.func()
def func(self):
print('in foo')
class son(Foo):
def func(self):
print('in son')
son()
结果:
in son

浙公网安备 33010602011771号