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"); } }
复制代码

 

posted @   高冷就是范儿  阅读(349)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示