|
参照网上教程interface的例子,我把它简化如下:
--------------------------------------------------------
interface Instrument {
void play();
String what();
void adjust();
}
class Wind implements Instrument {
public void play() {
System.out.println("Wind5.play()");
}
public String what() { return "Wind"; }
public void adjust() {}
}
public class Music {
public static void main(String[] args) {
Instrument orchestra = new Instrument;
orchestra = new Wind();
orchestra.play();
}
}
-----------------------------------------------------------
这太stupid了,完全可以不用interface,用如下代码替换
-----------------------------------------------------------
class Wind {
public void play() {
System.out.println("Wind5.play()");
}
public String what() { return "Wind"; }
public void adjust() {}
}
public class Music {
public static void main(String[] args) {
Wind orchestra = new Wind();
orchestra.play();
}
}
-------------------------------------------------------------
我不明白用interface倒抵有什么用,除了可以多重继承, 望高手指教~~~~~~~ |
|