class Note {
private String noteName;
private Note(String noteName) {
this.noteName = noteName;
}
public String toString() {
return noteName;
}
public static final Note
MIDDLE_C = new Note("Middle C"),
C_SHARP = new Note("C Sharp"),
B_FLAT = new Note("B Flat");
}
public class Music {
public static void tune(Instrument i) {
i.play(Note.MIDDLE_C);
}
public static void main(String[] args) {
Wind flute = new Wind();
tune(flute);
}
}
class Wind extends Instrument {
public void play(Note n) {
System.out.println("Wind.play()"+n);
}
}
class Instrument {
public void play(Note n) {
System.out.println("Instrument.play()");
}
}
红色的部分不是很理解,高人指点。。