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

 

相关文章:

  • 2021-08-23
  • 2021-06-07
  • 2022-02-18
  • 2021-12-24
  • 2021-12-12
  • 2022-12-23
  • 2022-02-08
  • 2021-10-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-04-07
相关资源
相似解决方案