How to implement polymorphism in Python?
How to implement polymorphism in Python?
How to implement polymorphism in Python?
solveurit24@gmail.com Changed status to publish February 13, 2025
Polymorphism occurs when different classes have the same method names and overriding parent class methods.
class Shape:
def area(self):
pass
class Circle(Shape):
def area(self, radius):
return 3.14 * radius * radius
class Square(Shape):
def area(self, length):
return length * length
circle = Circle()
square = Square()
print(circle.area(5)) # Output: 78.5
print(square.area(4)) # Output: 16solveurit24@gmail.com Changed status to publish February 13, 2025