//:c07:winderror.java
//Accidentally changing the interface.class NoteX{
public static final int MIDDLE_C = 0, C_SHARP = 1, C_FLAT = 2;
}class InstrumentX{
public void play(int NoteX){
System.out.println("InstrumentX.play()");
}
}class WindX extends InstrumentX{
//OOPS!Changes the method interface:
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);//Not the desired behavior;
}
}///:-
//结果输出的是:
InstrumentX.play()
为什么不是:
WindX.play(NoteX n)
解决方案 »
- getClass().getMethod()参数问题
- java执行mysqldump命令的问题
- 1+1/2!+1/3!+1/4!是怎么算
- 這樣問題,時可以時不能.謝謝.
- JAVA的编译问题
- java 中使用打印机的问题
- 高手入内(在线等待)查询出的数据集(ResultSet)不能传给字符串(String)
- 如何调整SUN机器的分辨率到1280*1024,在线等待!!!!!急急急急急急急急急
- 谁有比较好的中国象棋算法,可以借我参考一下吗?(40分)
- 为什么这样不能在ie5.5里面看结果!s说要我下载java虚拟机!我该如何处理阿!!
- 运行jar 出现问题......
- 初用,请教netbeans4中如何执行带参数得java程序?
public static final int MIDDLE_C = 0, C_SHARP = 1, C_FLAT = 2;
}class InstrumentX{
public void play(int NoteX){
System.out.println("InstrumentX.play()");
}
}class WindX extends InstrumentX{
//OOPS!Changes the method interface:
public void play( NoteX n){
System.out.println("WindX.play(NoteX n)");
}
}public class WindError{
public static void tune(WindX i){ //参数类型应该为: WindX
//...
i.play(NoteX.MIDDLE_C);
}
public static void main(String []args){
WindX flute = new WindX();
tune(flute);//Not the desired behavior;
}
}
WindX类型他继承了InstrumentX自然有public void play(int NoteX)方法,自己又新加方法
public void play( NoteX n),即重载。系统自己会根据参数选择调用哪个方法。