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

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

 

 

 

package com.hanqi.test;

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


}
package com.hanqi.test;

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

}
package com.hanqi.test;

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

}
package com.hanqi.test;

public class Music {

    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();

    }

}

 

posted @ 2016-09-22 19:03  -加勒比海带  阅读(2612)  评论(0编辑  收藏  举报