package polymorphism.music;
import polymorphism.music.Note;
class Imstrument{
public void play(Note n){
System.out.println("Imstrument.paly()");
}
}
class Wind extends Imstrument{
public void paly(Note n){
System.out.println("Wind.paly()"+n);
}
}
class A{
public static void tune(Imstrument i){
i.play(Note.MIDDLE_C);
}
public static void main (String[] args) {
Wind a1=new Wind();
tune(a1);
}
}我想要输出的是“Wind.paly()”但是输出的怎么是“Imstrument.paly()”请问您怎么回事?
package polymorphism.music;
import polymorphism.music.Note;
class Instrument{
void play(Note n){
System.out.println("Instrument.play() ");
}
}
class Wind extends Instrument{
void play(Note n){
System.out.println("Wind.play() "+n);
}
}
class A{
static void tune(Instrument i){
i.play(Note.MIDDLE_C);
}
public static void main (String[] args) {
Wind a1=new Wind();
tune(a1);
}
}