The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

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.

Message:

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.






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

Sponsored Links



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