相关疑难解决方法(0)

调用父级的父方法,该方法已由父级重写

如果在继承链中被另一个类覆盖,那么如何在继承链上调用多个类的方法呢?

class Grandfather(object):
    def __init__(self):
        pass

    def do_thing(self):
        # stuff

class Father(Grandfather):
    def __init__(self):
        super(Father, self).__init__()

    def do_thing(self):
        # stuff different than Grandfather stuff

class Son(Father):
    def __init__(self):
        super(Son, self).__init__()

    def do_thing(self):
        # how to be like Grandfather?
Run Code Online (Sandbox Code Playgroud)

python oop inheritance

28
推荐指数
2
解决办法
1万
查看次数

标签 统计

inheritance ×1

oop ×1

python ×1