Infosys Interview Question

Can you explain the concept of polymorphism in object-oriented programming

Interview Answer

Anonymous

Aug 29, 2024

Polymorphism allows objects of different classes to be treated as objects of a common superclass. It enables methods to be used interchangeably, where the specific method invoked is determined at runtime. This can be achieved through method overriding (runtime polymorphism) or method overloading (compile-time polymorphism). For example, if a superclass has a method display(), subclasses can provide their own implementation of display(). When display() is called on a subclass object, the overridden method in the subclass is executed, demonstrating runtime polymorphism."