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