Solution Review: Inheritance

This lesson discusses the solution for the inheritance problem in the previous lesson.

We'll cover the following

Solution:

Notice that in line 18 Square inherits from Rectangle and in line 22, it accesses the constructor of the Rectangle class using super(). If you remove super().__init__(x1, y1, x2, y2) from line 22, then code will give an error.

In the end, we created two instances of the Square class and calculated their area to test if the inheritance code is correct.

Get hands-on with 1200+ tech skills courses.