The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Thanks but...

Posted by Anish on November 28, 2001 at 3:14 PM

I thought that when a class extends a base class it can upcast to the base class type. So WindX would be included as a type InstrumentX. Since it doesnt work without an explicit cast, does this mean that overloading does not work with inheritance?

> The problem is in the tune method defined in WindError. The tune method takes a parameter of type InstrumentX. Because there is no play method on InstrumentX that takes a NoteX, an error is thrown. An explicit cast is needed on the incoming InstrumentX object to cast it to a WindX object. Then you can call the WindX's play method.

  • Overloaded Matt Gerrans November 28, 2001 at 4:09 PM (0)

Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us