What is Polymorphism ? How is Polymorphism achieved in C++ ?
Polymorphism is one of the most important principle of object oriented language. Polymorphism means many forms i.e. one interface multiple methods. The specific method to call depends on the nature of the situation. No matter what type of car it is the driving mechanism is the same. For example, you might have a program that defines three different types of stacks. One stack is used for integer values, one for character values, and one for floating-point values. Because of polymorphism, you can define one set of names, push() and pop() , that can be used for all three stacks. In your program you will create three specific versions of these functions, one for each type of stack, but names of the functions will be the same. The compiler will automatically select the right function based upon the data being stored. Thus, the interface to a stack—the functions push() and pop() —are the same no matter which type of stack is being used. C++ supports both run time and compile time polymorphism. Function overloading is a form of compile time polymorphism while dynamic binding is a form of runtime polymorphism.
