首页 > 代码库 > 作业-继承

作业-继承

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

 

 技术分享技术分享

package T092201;public class Instrument {    public void play()    {        System.out.println("弹奏乐器!");    }}package T092201;public class Wind extends Instrument{    public void play()    {        System.out.println("弹奏Wind!");    }    public void play2()    {        System.out.println("调用wind的play2");    }}package T092201;public class Brass extends Instrument {    //复写play方法    public void play()    {        System.out.println("弹奏brass!");    }    public void play2()    {        System.out.println("调用brass的play2!");    }}package T092201;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);    }}

技术分享

作业-继承