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.


Overloading with Inheritance

Posted by Anish on November 28, 2001 at 1:34 PM

Is it not possible to combine overloading with inheritance?
Take the following code from BruceEckel's Thinking in Java Edition 1, p263. He seems to suggest that overloading with inheritance is possible. I ran the following program and it seemed to work fine and called up the play() method in InstrumentX. Now I wanted to see if I could call up the play method in WindX instead. So I changed line 20 to " NoteX());" thus passing play() a NoteX instead of an int. But I keep getting an error. Whats wrong?

class NoteX {
public static final int
MIDDLE_C = 0, C_SHARP = 1, C_FLAT = 2;

class InstrumentX {
public void play(int noteX) {

class WindX extends InstrumentX {
public void play(NoteX n) {
System.out.println(" n)");

public class WindError {
public static void tune(InstrumentX i) {;
public static void main(String[] args) {
WindX flute = new WindX();


Sponsored Links

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