实现如下类之间的继承关系,并编写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); } }
时间: 2024-10-03 23:24:54