Question 11
Back to Exercise
What is the output of the following Python program?
class Report:
def render(self):
return f"[{self.header()}] {self.body()}"
def header(self):
return "REPORT"
def body(self):
return "empty"
class Sales(Report):
def body(self):
return "sales up 12%"
class Audit(Report):
def header(self):
return "AUDIT"
print(Sales().render(), "|", Audit().render())
- A [REPORT] empty | [REPORT] empty
- B [REPORT] sales up 12% | [REPORT] empty
- C [REPORT] sales up 12% | [AUDIT] empty Correct
- D AttributeError
Correct Answer: Option C
render() lives in Report, but self.header() and self.body() dispatch to each subclass's overrides.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!