java中接口实现多态举例



public
class Test4 { public static void main(String[] args){ Instrument ss[]={new Wind(),new Piano()}; for(Instrument i:ss){ tun(i); } } public static void tun(Instrument i){ i.play(); } } interface Instrument{ void play(); } class Wind implements Instrument{ public void play(){ System.out.println("wind can play"); } } class Piano implements Instrument{ public void play(){ System.out.println("Piano can play"); } }
原文地址:https://www.cnblogs.com/CodingAndRiding/p/7441314.html