016-003-007
Introduction to Polymorphism with Abstract Class
Easy
Problem Description
Introduction to polymorphism with abstract class
In this problem, you will create a program that implements Circle and Square subclasses extending an abstract Shape class, overrides the abstract method draw() in each subclass, and displays the result to standard output.
Learning Objective: Understand that abstract class type variables can hold different subclass objects and produce different behaviors
Overview
Assign Circle and Square objects to Shape type variables and call the same draw() method to get different outputs.
Specifications
- Define
abstract void draw()inShapeabstract class CircleextendsShapeand implementsdraw()to printDrawing a circleSquareextendsShapeand implementsdraw()to printDrawing a square- In main, assign each to a
Shapevariable and calldraw()
Output Format
Drawing a circle
Drawing a square
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