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

  1. Define abstract void draw() in Shape abstract class
  2. Circle extends Shape and implements draw() to print Drawing a circle
  3. Square extends Shape and implements draw() to print Drawing a square
  4. In main, assign each to a Shape variable and call draw()

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