Challenge 5: Inheritance
Solve an exercise on inheritance to brush up on the previous inheritance concepts.
We'll cover the following
Problem Statement
The code for the Rectangle
class is implemented below:
-
Create a
Square
class as a subclass ofRectangle
. -
Implement the
Square
constructor. The constructor should have only thex1
,y1
coordinates and thelength
of a side. Notice which arguments you’ll have to use when you invoke theRectangle
constructor while usingsuper
.
The following test cases will calculate the area of the square to check that the Square
class correctly inherits attributes and methods from Rectangle
.
Input
The coordinates and the length of the square
Output
Area of the square
Sample Input
Square([2, 3, 5])
x1 = 2, y1 = 3, length = 5
Sample Output
Area = 25
Get hands-on with 1200+ tech skills courses.