015-001-003

Basic Polymorphism: Shape Class

Easy

Problem Description

Basic polymorphism: Shape class

In this problem, you will create a program that implements Shape, Circle, and Rectangle classes using polymorphism to handle child class objects through parent class references, calculating and displaying the shape type, size, and area to standard output.

Learning Objective: Understand polymorphism handling child class objects with parent class reference

Create Shape class representing shapes, Circle and Rectangle classes inheriting from it. Handle child class objects with parent class reference and learn that overridden methods are called.

Input

Line 1: Shape type ("Circle" or "Rectangle")
Line 2: Size (integer)

Output

Shape Type: [Circle/Rectangle]
Size: [size]
Area: [area]

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