Polymorphism: The occurance of something in different forms or in the actual greek word of many forms. In the object oriented programming world that can mean practically anything so I am going to attempt to explain it in my own words.
First I am writing this article for two reasons.
One: for all those times I was asked (mostly job interviews) and there wasn't really time to explain it or when I hear the word polymorphisim used in the work place and the meaning is unclear by the context of the sentence. It is a rather complex subject when it all comes down to it.
In 1967, Christopher Strachey came up with the concept of polymorphism. But, to better understand Polymorphisim look at Monomorphism. A momomorphic language is strictly typed. A data type can have one and only one meaning. Which means that functions and procedures have a unique type that can not be violated. So one couldn't return an interface or an ancestor of an object. Therefore in monomorphic systems typing is very straight forward. That is easy to understand. A type can be ONE and ONLY one thing.
And in loose terms that is what polymorphism is "of many forms" If String is a decendant of object and a string is passed back from a function that is declared to return object that should be ok in a polymorphic system, since string decends from object.
According to Luca Cardelli and Peter Wegner, authors of "On Understanding Types, Data Abstraction, and Polymorphism," they have expanded the original polymorphic paridigm of Strachey to include four types in two catagories, ad hoc and universal. Thier observations look like this:
coercion / -- Ad hoc
parametric / -- Unviversal
The first type is coercion which is fairly straight forward. Coercion and overloading are somewhat similar and, again, according to the writings of Cardelli and Wegner the distinction becomes blurred at times. But there is still a distinction. A compiler generally overloads operators to achieve a result - convienence. For example if one was to add an integer to a double the outcome would be a double. The compiler converts the integer to a double. Look at this:
int i=2; double x=2.0; double total = i+x;
The outcome would be 4.0. Try it it works. It works because the compiler is coerced into converting the int to a double. Converting a double to an integer would cause a loss of percision so it happens the other way around. But the circutry doesn't matter, in fact there are developers that don't even know it's happening. It would appear that the operator + has many forms. Is that polymorphic? That depends... maybe not truly polymorphic, more like a set of monomorphic functions that achieve the same result.
Anyone that has been coding in a second generation language (even 4th generation for that matter) knows of method overloading. The compiler includes the parameters of a function in the declaration or signature of the method so multiple methods with the same name appear different as long as the parameters are different. A class can have two methods to perform the same task based on different parameter types. An class that contains a list of strings, maybe names, may have two methods to retrieve those names from the list. First a getName(String) method that retrieves a particular name, where getName(int) retrieves a name in a certain position. Also, getName() may retrieve a name in the next position. Are these methods polymorphic? The same function name seems to take different parameters. Is this behavior “of many forms”? Not exactly true polymorphism but more of a smoke screen. The methods themselves are not operating on a wide range of types, meaning the parameters are not changing or being interpreted as different types rather they are different methods, which means they are not executing the same code. Infact, they are executing different code for each situation. Although it appears to be polymorphic it is actually a set of monomorphic functions posing to be polymorphic.
When a method can operate efficiently on a range of types with similar structure the parameters of the method or function can have different meaning. Unlike overloading, the method actually takes an object that can assume the identity of it's superclass without re-typing it. e.g. Say class C extends or decends from class B which in turn decends from class A. If the signature of a method includes a parameter type of class C but accepts class A and treats it the same as if it were of type class C, that would be true polymorphism. Because the actual parameter passed in can be treated indentical to the superclass and execute the same code as if it were the superclass. Remember “of many forms”. The parameter is actually changing forms from the subclass to the superclass and the same code is being executed on either type... that's polymorphism!
Also subtype polymorphism more closely represents object oreiented programming. In this version one could look at objects as belonging to a heirarchy or structure which allows it to belong to many different classes. In inclusion polymorphism, the heirarchy of classes is polymorphism or "of many forms". Being that a class can decend into another class and begin to take other shapes, it is exhibiting polymorphic behavior. While in Parametric polymorphism a function can operate on a range of types of similar structure and treat them similar executing the same code, inclusion polymorphism the type is actually a part of many classes.
In retrospect there are two major catagories of polymorphism, ad-hoc and universal. While ad-hoc polymorphism (i.e. coersion and overloading) seems to exhibit polymorphic behavior it is instead monomorphic at the heart. Whereas, universal polymorphism (i.e. parameteric and inclusion) is more the truer form of polymorphism, because it can truely treat a type and a subtype the same.
It would seem that there are a lot of polymorphic labels that aren't really polymorphic at all but rather a set of monomorphic features. On the other hand, is not beuaty in the eyes of the beholder? If one thought it was polymorphic and by all intents and purposes it seemed that way would that not be in itself, polymorphic? It would seem to me. Call it what you want.
So, mentioning the word polymorphism is more like the pickle. A pickle is actually a pickled cucumber but we just call it a pickle. As well, when we talk of polmorphism we are talking of subtype polymorphism. It is the truer version. Sub-type polymorphism more closely resembles inclusion polymorphism and explains object heirarchies.
I've included a link to a very well thoughtout paper on the subject from much bigger minds than mine. Infact most of my information comes from here.