016-001-008

Basics of Abstract Classes and Methods

Easy

Problem Description

Basics of Abstract Classes and Methods

In this problem, you will create a program that defines an abstract class Shape with an abstract method describe(), implements it in Circle and Square subclasses, and displays the result to standard output.

Learning Objective: Understand defining abstract classes and implementing abstract methods in subclasses

Overview

Define an abstract method describe() in abstract class Shape and implement it in Circle and Square.

Specifications

  1. Define abstract void describe() in abstract class Shape
  2. Circle extends Shape, describe() prints I am a circle.
  3. Square extends Shape, describe() prints I am a square.
  4. In main, assign Circle and Square to Shape variables and call describe()

Output Format

I am a circle.
I am 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