Graphic Design Software
A graphic design software company is developing their next-gen software. They are implementing a feature to calculate the area of various shapes. They have started by creating a generic Shape class, but they need to extend it with two more specific classes: Circle and Rectangle. Your task is to implement this feature.
Start by creating a base class Shape with a method area() that returns 0. This method should be overridden in two derived classes: Circle and Rectangle. Both Circle and Rectangle should inherit from the Shape class and both should have an area() method that calculates and returns the area of the respective shape.
The
Circleclass should be initialized with a radius,r. Thearea()method of theCircleclass should return the area calculated as.The
Rectangleclass should be initialized with a length,l, and a width,w. Thearea()method of theRectangleclass should return the area calculated as.
Input | Output |
|---|---|
| 78.53981633974483 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB