实现如下类之间的继承关系,并编写Music类来测试这些类。

1,实现如下类之间的继承关系,并编写Music类来测试这些类。

package com.chuoji.text01;

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

    public void play()
    {
        System.out.println("弹奏brass");
    }
    public void play2()
    {
        System.out.println("调用brass的play2");
    }
    
}

public class Music {
    
    public static void tune(Instrument i)
    {
        i.play();
    }
     public static void main(String[] args)
     {
        Wind w= new Wind();
        Brass b= new Brass();
        tune(w);
        tune(b);
     }
    
}
public class Music {
    
    public static void tune(Instrument i)
    {
        i.play();
    }
     public static void main(String[] args)
     {
        Wind w= new Wind();
        Brass b= new Brass();
        tune(w);
        tune(b);
     }
    
}

 


    



posted @ 2016-09-23 09:55  戳记  阅读(1824)  评论(0编辑  收藏  举报