(Comparable interface) Write Rectangle class that implements the Comparable interface. Override the equals method so that two Rectangle objects are equal if their areas are the same.

Respuesta :

Answer:

class Rectangle(object):

   def __init__(self, area):

       self.area = area

   def __eq__(self,other):

       return self.area == other.area

d = Rectangle(43)

e = Rectangle(23)

print(d == e)

Explanation:

The python program defines a class called Rectangle that accepts one argument 'area' and compare one instance of the object with another instance. The '__eq__' method helps to define the equality of the instance based on their area values. If the areas are equal, the equality statement returns true and false if not.