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
Shapeabstract class: definesgetArea()anddescribe()as abstract methodsCircle: has a radius field, area is calculated asradius * radius * 3.14Rectangle: has width and height fields, area is calculated aswidth * heightdescribe()returns a string in the format"Shape: {name}, Area: {area}"- In Main, create
Circle(5)andRectangle(4, 6), then calldescribe()
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