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