Answer:
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
area = self.length*self.width
return area
class Box (Rectangle):
def __init__(self, length, width, height):
super().__init__(length, width)
self.height = height
def volume(self):
volume = self.length * self.width * self.height
return volume
def area(self):
area = 2*(self.length*self.width) + 2*(self.length*self.height) + 2*(self.width*self.height)
return area
rec_1 = Rectangle(2,4)
box_1 = Box(2,2,6)
print(box_1.length)
print(box_1.area())
print(rec_1.length)
print(rec_1.area())
Explanation:
The programming language used is python.
class Rectangle
The class Rectangle is created with attributes length and width.
The class attributes are initialized using the __init__ constructor.
In the rectangle class, a method/function is declared to return the area of the rectangle.
class Box
This class is a child of rectangle and it inherits all its attributes and methods,
It has an additional attribute of depth and its constructor is used to initialize it.
The class contains a volume function, that returns the volume and an override function 'area()' that displaces the area from the parent class.
Finally, some instances of both classes are created.