147k views
0 votes
(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.

User LBPLC
by
6.8k points

1 Answer

3 votes

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)

Step-by-step 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.

User Nebi
by
6.2k points