"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object.
Example: function overloading, function overriding, virtual functions.
Another example can be a plus ‘+’ sign, used for adding two integers or for using it to concatenate two strings.
An example would be: A "vehicle" class can be a part of a inheritance heirachy where derived classes are "sedan" and "SUV". Derived from "sedan" could be "Corolla", and derived from "SUV" could be "Pathfinder".
CAR / SUV SEDAN / PATHFINDER COROLLA
Now, using such an example, it is true that any object below in a heirarchy is also something that is directly up in the heirarchy. Hence, Pathfinder "is a" SUV, and SUV "is a" CAR. Also, Pathfinder "is a" CAR. Hence, using pointers of Base classes (higher in an inheritance heirarchy) can be assigned to objects of derived classes and can be used in a unified manner with the use of virtual functions. Hence, Polymorphism.
(The plus "+" operator example used above would not be correct, as that is actually an overloaded operator (in the case the last poster presumed) and not precisely polymorphism).
Above answer was rated as good by the following members: anellona
RE: What is polymorphism? Explain with an example?
An example would be: A vehicle class can be a part of a inheritance heirachy where derived classes are sedan and SUV . Derived from sedan could be Corolla and derived from SUV could be Pathfinder .
CAR / SUV SEDAN / PATHFINDER COROLLA
Now using such an example it is true that any object below in a heirarchy is also something that is directly up in the heirarchy. Hence Pathfinder is a SUV and SUV is a CAR. Also Pathfinder is a CAR. Hence using pointers of Base classes (higher in an inheritance heirarchy) can be assigned to objects of derived classes and can be used in a unified manner with the use of virtual functions. Hence Polymorphism.
(The plus + operator example used above would not be correct as that is actually an overloaded operator (in the case the last poster presumed) and not precisely polymorphism).
Polymorphism is acquiring many forms . as it has been stated that c++ has the property of polymorphism.Like as someone said the eg of vehicle...it can be said that the particular operation can acquire one or many forms