016-001-003

Abstract Class: Basic Concept

Easy

Problem Description

abstract class: Basic Concept

In this problem, you will create a program that implements an abstract class Shape and a concrete class Rectangle, calculates the area of a rectangle with width 4 and height 5, and displays the result to standard output.

Learning Objective: Understand basics of abstract classes and abstract methods

Overview

Abstract classes cannot be instantiated directly. They must be inherited by subclasses. Abstract methods must be implemented in subclasses.

Specifications

  • Define abstract double getArea() method in abstract class Shape
  • Implement getArea() in class Rectangle (which extends Shape) to return width × height
  • Create a Rectangle instance with width 4 and height 5, then display its area

Output Format

Area: 20

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