标签:
1 package com.hanqi.z1p1; 2 3 public class Instrument { 4 5 public void play() 6 { 7 System.out.println("弹奏乐器"); 8 } 9 10 11 12 }
1 package com.hanqi.z1p1; 2 3 public class Wind extends Instrument { 4 5 public void play() 6 { 7 System.out.println("弹奏Wind"); 8 } 9 10 11 public void play2() 12 { 13 System.out.println("调用Wind的play2"); 14 } 15 16 }
1 package com.hanqi.z1p1; 2 3 public class Brass extends Instrument{ 4 5 public void play() 6 { 7 System.out.println("弹奏Brass"); 8 } 9 10 public void play2() 11 { 12 System.out.println("调用Brass的play2"); 13 } 14 15 16 17 }
1 package com.hanqi.z1p1; 2 3 public class Music { 4 5 6 public static void tune(Instrument i) 7 { 8 i.play(); 9 } 10 11 12 public static void main(String[] args) { 13 // TODO 自动生成的方法存根 14 15 Wind w=new Wind(); 16 tune(w); 17 Brass b =new Brass(); 18 tune(b); 19 20 21 22 23 24 } 25 26 }
运行结果:
标签:
原文地址:http://www.cnblogs.com/miss123/p/5517827.html