编写Music类

package a;

public class Instrument {
    public void play()
    {
        System.out.println("弹奏乐器");
    }

}
package a;

public class Wind extends Instrument {
    public void play()
    {
        System.out.println("弹奏Wind");
    }
    public void play2()
    {
        System.out.println("调用Wind的play2");
    }

}
package a;

public class Brass extends Instrument{
    public void play()
    {
        System.out.println("弹奏Brass");
    }
    public void play2()
    {
        System.out.println("调用Brass的play2");
    }


}
package a;

public class Music {    
    
    public static void tune(Instrument i)
    {
        i.play();
    }

    public static void main(String[] args) {    

         Wind a=new Wind();
         
         Music.tune(a);
         a.play2();
        
        Brass b=new Brass();
        
        Music.tune(b);
        b.play2();
    }

}

posted @ 2016-05-22 23:30  凌零聆  阅读(235)  评论(0编辑  收藏  举报