首页 > 代码库 > 18.实现如下类之间的继承关系,并编写Music类来测试这些类。

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

技术分享

技术分享

package zhongqiuzuoye;public class Instrument {        public void play()    {        System.out.println("弹奏乐器");    }}
package zhongqiuzuoye;public class Wind extends Instrument{        public void play()    {        System.out.println("弹奏wind");    }    public void play2()    {        System.out.println("调用wind的play2");    }    }
package zhongqiuzuoye;public class Brass extends Instrument{    public void play()    {        System.out.println("弹奏brass");    }    public void play2()    {        System.out.println("调用brass的play2");    }}
package zhongqiuzuoye;public class Music {    public static void tune(Instrument i){        i.play();        }        public static void main(String[] args)         {            Instrument i= new Instrument();            i.play();            Wind w= new Wind();            w.play();            w.play2();                        Brass b= new Brass();            b.play();            b.play2();       }}

 

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