Question: Shape Class: Create a class named Shape with the following methods: calculateArea ( ) : Returns 0 . 0 ( to be overridden by subclasses

Shape Class:
Create a class named Shape with the following methods:
calculateArea(): Returns 0.0(to be overridden by subclasses).
display(): Prints "Area: " followed by the calculated area.
Circle Class (extends Shape):
Create a subclass named Circle that extends Shape.
Add a private attribute radius and a constructor that initializes it.
Override the calculateArea method to calculate the area of a circle using the formula \pi * radius * radius.
Rectangle Class (extends Shape):
Create another subclass named Rectangle that extends Shape.
Add private attributes length and width, and a constructor that initializes them.
Override the calculateArea method to calculate the area of a rectangle using the formula length * width.
Main Class:
In the Main class, create instances of Circle and Rectangle using sample dimensions.
Call the display method on each instance to print the calculated areas.
Testing:
Compile and run your program to ensure that it produces the correct output, displaying the areas of the circle and rectangle.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!