package bbb; public class Instrument { public void play(){ System.out.println("弹奏乐器"); } } class Wind extends Instrument{ public void play(){ System.out.println("弹奏Wind"); } public void play2(){ System.out.println("调用Wind的play2"); } } class Brass extends Instrument{ public void play(){ System.out.println("弹奏Brass"); } public void play2(){ System.out.println("调用Brass的play2"); } }
package bbb; public class Music { public static void tune(Instrument i) { i.play();} public static void main(String[] args) { Instrument a=new Instrument(); Wind b=new Wind(); Brass c=new Brass(); tune(a); tune(b); tune(c); } }
class Monkey { public void speak(){ System.out.println("咿咿呀呀..."); } } class People extends Monkey{ People(String s) { // TODO 自动生成的构造函数存根 } public People() { // TODO 自动生成的构造函数存根 } { // TODO 自动生成的构造函数存根 } public void speak(){ System.out.println("小样不错嘛会说话了!"); } void think(){ System.out.println("别说话,认真思考!"); } } public class E{ public static void main(String[] args) { People a=new People(); People b=new People(); a.speak(); b.think(); } }