Goldman Sachs Interview Question
Software Engineer / DevelopersPolymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.
You can use implementation inheritance to achieve polymorphism in languages such as C++ and Java.
Base class object's pointer can invoke methods in derived class objects.
You can also achieve polymorphism in C++ by function overloading and operator overloading.
Polymophism is the ability to provide mutilple implementations of an action and select the correct implementation based on the surounding context.
For example , a class can have two versions of a method with different parameters ;
Or the same method can be defined both in base class and sub class ,the latter overriding the former for the instance of subclass.
using base class pointer/ reference u call derived class methods is called polymorphism.
- sachin323 November 01, 2010