Monday, January 2, 2012
What is wrong with the following Java code? (Emphasis on Polymorphism)?
Something I find useful is to ign real-life objects to the cles. So let's say Cl1 is a cl Vehicle(), with cles 2 and 3 being Car() and Truck() respectively. So we make a Car() and Truck() and store them in c2 and c3. uming that classes can be cast (since some previous posts already told you this), you can think about this in a more real world sense. "(Class1) c3" casts c3 as an instance of Class1. In other words, it casts a Truck() as a Vehicle(), which should make sense in real life. Then it tries to cast what we have, a Vehicle(), as a Car() and then stores it in a variable of type Car(). Without giving the answer, try to take this and see if the rest will work. Will it compile? Will it run? Hope this helped at all...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment