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 Circle class should be initialized with a radius, r. The area() method of the Circle class should return the area calculated as .
  • The Rectangle class should be initialized with a length, l, and a width, w. The area() method of the Rectangle class should return the area calculated as .
Input
Output
circle = Circle(5); print(circle.area()); rect = Rectangle(5, 10); print(rect.area())
78.53981633974483 50
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in