What is the output of the following? “`python class A: def method(self): return ‘A’ class B(A): def method(self): return super().method() + ‘B’ class C(A): def method(self): return super().method() + ‘C’ class D(B, C): pass print(D().method()) “`

Python Developer Hard

Python Developer — Hard

What is the output of the following? “`python class A: def method(self): return ‘A’ class B(A): def method(self): return super().method() + ‘B’ class C(A): def method(self): return super().method() + ‘C’ class D(B, C): pass print(D().method()) “`

Key points

  • Inheritance in Python allows subclasses to override methods from parent classes
  • The super() function allows subclasses to access and call methods from parent classes
  • The order of inheritance determines the method resolution order in Python

Ready to go further?

Related questions