Calling an overridden method, superclass an calls overridden method

后端 未结 4 1943
情深已故
情深已故 2021-01-08 00:39

This code throws an exception, AttributeError, \"wtf!\", because A.foo() is calling B.foo1(), shouldn\'t it call A.foo1()? Ho

4条回答
  •  渐次进展
    2021-01-08 00:58

    It is working as intended, as 100% of world programming languages work. Subclass overrides ALL methods of parent class.

    However if you really really want to call the A.foo1() you might be able to do it like this (I cannot guarantee). And in any case you must not do this as this is against all principles of good programming.

     class A(object):
    
        def foo(self):
            A.foo1(self)
    

提交回复
热议问题