类的继承小问题:

Posted zhao159461

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了类的继承小问题:相关的知识,希望对你有一定的参考价值。

带有封装私有化属性的继承类:

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

  

以上是关于类的继承小问题:的主要内容,如果未能解决你的问题,请参考以下文章