Skip to main content

Practice ยท 3 of 3

Predict the MRO chain

Without running it first (then run it!), implement the classes so that chain() returns the exact call order of who() across the hierarchy when called on a D instance. Classes: A defines who returning 'A' and logs to a shared list. B(A) overrides who to log 'B' then super().who(). C(A) overrides who to log 'C' then super().who(). D(B, C) overrides who to log 'D' then super().who(). chain() must reset the log, call D().who(), and return the list โ€” expected ['D', 'B', 'C', 'A'] following the MRO Dโ†’Bโ†’Cโ†’A.

Difficulty: advanced

Back to lesson: Practice: Attribute Lookup Practice