Inheritance: extending a base class

Inheritance lets a child class reuse and specialise behaviour from a parent class. Use it when there's a genuine "is-a" relationship.

Implement a base class Shape with:

  • A method area() that returns 0 (default)
  • A method describe() that prints Shape with area: <area>

Then implement two subclasses:

  • Circle(radius) — overrides area() with π × r² (use 3.14159, round to 2 decimal places)
  • Rectangle(width, height) — overrides area() with width × height

Your program receives comma-separated shape definitions:

  • circle:<r>
  • rect:<w>:<h>

For each, call describe() and print the result.

Input:  circle:5,rect:4:6
Output: Shape with area: 78.54
        Shape with area: 24

Constraints

  • Circle area rounded to 2 decimal places. Rectangle area is always an integer — print without decimals.
  • Use inheritance (extend/subclass) — do not copy the describe method into each subclass.
Ad SpaceGoogle AdSense active for guests & free-tier learners.