Python Programming - Polymorphism - Discussion
Discussion Forum : Polymorphism - General Questions (Q.No. 40)
40.
Consider the following code:
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
What concept is demonstrated in this code?
Answer: Option
Explanation:
This code demonstrates operator overloading using the
__sub__()
method to customize the behavior of the subtraction operator (-
) for instances of the class.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers