Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Use super() Across a Multi-Level Inheritance Chain

Practice using super() to ensure cooperative initialization across multiple inheritance levels.

Python practice15 minInheritance & PolymorphismIntermediateLast updated April 8, 2026

Problem statement

You are given a three-level inheritance chain: Base <- Mid <- Leaf. Each class should record its initialization by appending a label to an instance list attribute in the correct order (Base first, then Mid, then Leaf). Implement Mid.__init__ and Leaf.__init__ so that they cooperate with Base using super(). After construction, the Leaf instance's order attribute should be ['Base', 'Mid', 'Leaf']. Implementations that fail to call the parent initializer (or call it incorrectly) may produce the wrong order or cause errors. Use super() to call the parent initializer.

Task

Implement constructors that use super() so that each class in a chain contributes to instance initialization in order.

Examples

Constructing Leaf

Input

get_init_order()

Output

['Base', 'Mid', 'Leaf']

Leaf.__init__ should call super().__init__ which in turn will call Base.__init__ through Mid, producing the ordered list.

Input format

Single expression calling a function or constructing a class, e.g., get_init_order() or Leaf().order

Output format

A list showing initialization order, e.g. ['Base', 'Mid', 'Leaf']

Constraints

Do not modify Base.__init__. Implement Mid.__init__ and Leaf.__init__ using super(). No external libraries.

Samples

Sample 1

Input

Mid().order

Output

['Base', 'Mid']

Mid must call Base's initializer so instances of Mid have both 'Base' and 'Mid' in order.