package com.lianxi; public class Instrument { public void play() { System.out.println("弹奏乐器"); } }
package com.lianxi; public class Wind extends Instrument { public void play() { System.out.println("弹奏Wind"); } public void play2() { System.out.println("调用Wind的play2"); } }
package com.lianxi; public class Brass extends Instrument { public void play() { System.out.println("弹奏brass"); } public void play2() { System.out.println("调出brass的play2"); } }
package com.lianxi; public class Music { //调用对象I的play public static void tune(Instrument i) { i.play(); } public static void main(String[] args) { // TODO 自动生成的方法存根 //调用turn方法,以Wind类对象为参数 Wind w=new Wind(); tune(w); //调用turn方法,以Brass类对象为参数 Brass b=new Brass(); tune(b); }
时间: 2024-09-30 13:03:08