Hierarchical Inheritance

Easy Multiple & Virtual Inheritance
Solve in Playground →

Problem Statement

Create a `Shape` base class with a public string `color`. Create `Circle` and `Square` classes that both inherit from `Shape`. Read a color string, instantiate both `Circle` and `Square`, assign the color to both, and print their colors on separate lines.

Input Format

A single string representing the color.

Output Format

Print 'Circle: [color]' and 'Square: [color]'.

Constraints

None

Sample Input

Red

Sample Output

Circle: Red
Square: Red

Explanation

Hierarchical inheritance occurs when more than one derived class inherits from a single base class.

Starter Code

#include <iostream>
#include <string>

class Shape {
public:
    // Write your code here
};

class Circle {
    // Inherit Shape
};

class Square {
    // Inherit Shape
};

int main() {
    // Read input, instantiate objects, and print
    return 0;
}

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