Classes of 2D Geometric Shapes
In the realm of 2-dimensional geometrical shapes, polygons form the basics. In this challenge, your task is to create classes representing four types of polygons: Polygon, Triangle, Rectangle, and Pentagon.
A polygon is defined by its number of sides. Therefore, the Polygon
class should contain an attribute sides
representing the number of sides of the polygon.
The Polygon
class also needs a method describe()
which prints "A polygon" when called.
Next, create Triangle
, Rectangle
, and Pentagon
classes that inherit from the Polygon
class. Each of these classes should override the describe()
method to print "A triangle", "A rectangle", and "A pentagon" respectively, when called. This way, each specific type of polygon will be able to announce what it is when the describe()
method is called.
Input | Output |
---|---|
| A polygon |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB