Composition: Has-a relationship

Easy Composition & Aggregation
Solve in Playground →

Problem Statement

Implement a `Car` class that strictly contains an `Engine` class. The `Engine` class takes a `power` parameter. The `Car` class should instantiate the `Engine` inside its own `__init__` method (strong lifecycle). Read an integer for power, instantiate the Car, and print the engine power.

Input Format

A single integer representing engine power.

Output Format

Print 'Engine: [power]HP' and on the next line 'Car created'.

Constraints

power > 0

Sample Input

400

Sample Output

Engine: 400HP
Car created

Explanation

Composition represents a strict 'has-a' relationship where the child object (Engine) cannot exist without the parent object (Car).

Starter Code

class Engine:
    # Define __init__ with power
    pass

class Car:
    # Define __init__ to instantiate Engine internally
    pass

if __name__ == '__main__':
    power = int(input().strip())
    # Instantiate Car and print details
    pass

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used