标签:
//Instrument类 package 乐器; public class Instrument { public void play() { System.out.println("弹奏乐器"); }
//Wind类 package 乐器; public class Wind extends Instrument { public void play() { System.out.println("弹奏Wind"); } public void play2() { System.out.println("调用Wind的play2"); } }
//Brass类 package 乐器; public class Brass extends Instrument { public void play() { System.out.println("弹奏Brass"); } public void play2() { System.out.println("调用Brass的play2"); } }
//Music类 package 乐器; public class Music { public static void tune(Instrument i) { i.play(); } public static void main(String[] args) { Wind a=new Wind(); tune(a); a.play2(); Brass b=new Brass(); tune(b); b.play2(); } }
运行结果
标签:
原文地址:http://www.cnblogs.com/mutougezi/p/5518050.html