Interface of constant values question

I am trying to get the following to compile.  I am not sure how the syntax works when using an interface that only contains constant values.

The "play" method of both base class "InstrumentX" and derived class "WindX" use the constants in interface NoteX, however, since NoteX resolves to a constant int I get the following error.  

How do I remedy the situation?
----------------------------------ERROR-------------------------------------
C:\java\code\c08>javac WindError.java
WindError.java:20: play(NoteX) in InstrumentX cannot be applied to (int)
    i.play(NoteX.MIDDLE_C);
-----------------------------------CODE--------------------------------------
//: WindError.java
 interface NoteX {
        public static final int
                MIDDLE_C = 0, C_SHARP = 1, C_FLAT = 2;
      }
class InstrumentX implements NoteX {
  public void play(NoteX n ) {
    System.out.println("InstrumentX.play()");
  }
}
class WindX extends InstrumentX {
    public void play(NoteX n ) {
    System.out.println("WindX.play(NoteX n )");
  }
}
public class WindError {
  public static void tune(InstrumentX i) {
    i.play(NoteX.MIDDLE_C);
  }
  public static void main(String[] args) {
    WindX flute = new WindX();
    tune(flute);   }
} ///:~
kellyputtyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tommy BraasCommented:
When you specify that a method accepts a parameter of type NoteX, you have to ensure that you pass a class instance which does just that.
Tommy BraasCommented:
In this case you're trying to pass an int. Even though that int is defined in your interface, the int itself can never be a NoteX.

Change your interface to an abstract class, and let the InstrumentX extend it.

Like:

 abstract class NoteX {
   private int note;
   private NoteX(int note) {
      this.note = note;
   }
   
   public static final NoteX MIDDLE_C = new NoteX(0);
   public static final NoteX C_SHARP = new NoteX(1);
   public static final NoteX C_FLAT = new NoteX(2);
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tommy BraasCommented:
;-D
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.