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 classShape - Implement
getArea()in classRectangle(which extendsShape) to return width × height - Create a
Rectangleinstance 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