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?
C:\java\code\c08>javac play(NoteX) in InstrumentX cannot be applied to (int);
 interface NoteX {
        public static final int
                MIDDLE_C = 0, C_SHARP = 1, C_FLAT = 2;
class InstrumentX implements NoteX {
  public void play(NoteX n ) {
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();
    tune(flute);   }
} ///:~
Who is Participating?
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.


 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);
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:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.