package com.cn.test10;
//不仅是继承类覆盖可以实现多态,实现接口亦可以实现多态
public class test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
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");
}
}