Nothing like a challenging question that combines both
Java, and American pop culture.
The son wants a car. A Dodge is-a car. By the way, an Al Bundy Dodge refers to the broken down Dodge car that Al Bundy always complained about in the TV show 'Married with Children.'
Married with Children TV Show The point is, the son wants a car, and a Dodge
is-a car. If you want something generic, like a car, and you get one, a specific type of car, then life is good. This is polymorphism in action. When you want a certain type of object, any subtype of that object will suffice.
On the other hand, the daughter wants a very specific type of car - a mercedes. A beaten up old dodge is not a mercedes. A brand new BMW isn't a Mercedes either. The daughter was very specific - she didn't want just a car, but instead, a very specific type of car. Since she didn't get the type that she wanted, she was not happy.
The same thing applies in Java. When you want an Object, any old Object will do. If you want a java.lang.Object, and I give you a java.awt.Color, life is good; if I give you a
String, life is good; if I give you a Byte, life is good. On the other hand, if you want a String, and I give you a Byte, Object or java.awt.Color, there will be problems.
With polymorphism, you can ask for a general object, and be given any subclass; but if you are given something more general that the type you are asking for, there will be problems. This is how polymorphism is unidirectional.
Shoot me an email if you have any more questions: male att cameronmckenzie dawt com
-Cameron McKenzie
[ February 25, 2007: Message edited by: Cameron W. McKenzie ]