This is in Python Write a Rectangle class that must be instantiated with two attributes: .length and .width. Add an .ar
Posted: Tue Jul 12, 2022 8:10 am
This is in Python
Write a Rectangle class that must be instantiated with twoattributes: .length and .width. Add an .area() method to theclass that returns the area (length * width) of the rectangle.
Then write a Square class that inherits from the Rectangle classand is instantiated with a single attribute called .side_length.Test your Square class by instantiating a Square with a.side_length of 4. Calling .area() should return 16.
Set the .width property of your Square instance to 5. Then call.area() again. The return value should be 20.
Be careful to define behaviors so that they reflectexpectations, and use class hierarchies with caution.
Write a Rectangle class that must be instantiated with twoattributes: .length and .width. Add an .area() method to theclass that returns the area (length * width) of the rectangle.
Then write a Square class that inherits from the Rectangle classand is instantiated with a single attribute called .side_length.Test your Square class by instantiating a Square with a.side_length of 4. Calling .area() should return 16.
Set the .width property of your Square instance to 5. Then call.area() again. The return value should be 20.
Be careful to define behaviors so that they reflectexpectations, and use class hierarchies with caution.