The quiz where the difficulty automagically adapts to the player's Python knowledge
This is a question page. You can use this page to bookmark a question. Start a new quiz!
Question #545
class Foo(object):
def __init__(self):
self.__method()
def __method(self):
print('42')
class MoreFoo(Foo):
def __method(self):
print('41')
MoreFoo()
As __method() is a private method (recognisable by the double underscores __ ), it cannot be overridden by simply defining it as __method(self) in the subclass (to avoid accidental override). To force overridding, it has to be redefined as def _Foo__method(self): . This is called name mangling. (stackoverflow.com/questions/14898197/override-private-met...)
Question difficulty: 🔵🔵🔵🔵🔵