016-003-010

Shape Polymorphism

Easy

Problem Description

Shape Polymorphism

In this problem: You will implement concrete classes Circle and Rectangle that extend the abstract class Shape, and create a program that uses polymorphism to display each shape's information to standard output.

Learning Objective: Understand the basics of abstract class inheritance and polymorphism

Overview

The Shape abstract class defines abstract methods getArea() and describe(). Circle and Rectangle provide concrete implementations of these methods.

Specifications

  • Shape abstract class: defines getArea() and describe() as abstract methods
  • Circle: has a radius field, area is calculated as radius * radius * 3.14
  • Rectangle: has width and height fields, area is calculated as width * height
  • describe() returns a string in the format "Shape: {name}, Area: {area}"
  • In Main, create Circle(5) and Rectangle(4, 6), then call describe()

Output Format

Shape: Circle, Area: 78.5
Shape: Rectangle, Area: 24.0

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up