Challenge 5: Inheritance

Solve an exercise on inheritance to brush up on the previous inheritance concepts.

Problem Statement

The code for the Rectangle class is implemented below:

  1. Create a Square class as a ​subclass of Rectangle.

  2. Implement the Square constructor. The constructor should have only the x1, y1 coordinates and the length of a side. Notice which arguments you’ll have to use when you invoke the Rectangle constructor while using super.

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.