ProgrammingVery hardWipro · Accenture · Capgemini pattern

What does the following Python 3 code print? class Base: def greet(self): return "base" class Mid(Base): def greet(self): return "mid-" + super().greet() class Top(Mid): def greet(self): return "top-" + super().greet() print(Top().greet())

  1. A. top-mid
  2. B. base-mid-top
  3. C. top-mid-base
  4. D. top-base

Correct answer: C. top-mid-base

Each class's super().greet() calls the next class up the MRO, so the calls chain Top -> Mid -> Base, concatenating all three strings.

More Python Programming questions

Exams that ask this topic