Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Use Multiple Inheritance to Combine Two Parent Behaviors

Learn how to use cooperative multiple inheritance with super() to combine behaviors from two parent classes into a single child class.

Python practice30 minInheritance & PolymorphismAdvancedLast updated April 8, 2026

Problem statement

You will build a small class hierarchy that demonstrates cooperative multiple inheritance in Python. Create an Animal base class and two behavior mixin-like parents, Flyer and Swimmer. Each parent should accept and store its own initialization parameter and should cooperate with other classes using super() and keyword arguments so that a concrete child class Duck can inherit both behaviors without duplicated initialization. The Duck class should: - Initialize name (from Animal), wing_span (from Flyer) and swim_speed (from Swimmer) using cooperative multiple inheritance (super() and keyword args). - Provide a moves() method that returns a list of action strings in the order: flyer action first, swimmer action second. - Provide a describe() method that returns a single string in the form: "{name}: fly({wing_span}), swim({swim_speed})". Do not call parent __init__ methods directly by name (e.g., Flyer.__init__(...)). Use super() and keyword arguments so the hierarchy remains cooperative and safe for further subclassing.

Task

Implement parent classes that cooperate via super() and a child class that combines both behaviors without duplicating initialization or breaking the method resolution order.

Examples

Combine flying and swimming

Input

Duck('Daffy', 1.2, 3.4).describe()

Output

Daffy: fly(1.2), swim(3.4)

Duck should collect both behaviors and format them into a single description string.

Input format

A class Duck(name, wing_span, swim_speed) is instantiated. Tests will call methods like .describe(), .moves() or inspect attributes.

Output format

Return values from the called methods. describe() returns a string, moves() returns a list of strings; attributes are basic types.

Constraints

Use cooperative multiple inheritance. Each parent class must call super().__init__(**kwargs) so that Duck can initialize all required attributes by calling super().__init__(name=..., wing_span=..., swim_speed=...). Do not directly invoke parent class __init__ by class name.

Samples

Sample 1

Input

Duck('Mallard', 0.8, 2.5).describe()

Output

Mallard: fly(0.8), swim(2.5)

The child Duck exposes both parent behaviors and properly formatted values.