首页 > 其他 > 详细

继承1

时间:2016-05-22 21:28:57      阅读:172      评论:0      收藏:0      [点我收藏+]

技术分享

 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 }

运行结果:

技术分享

继承1

原文:http://www.cnblogs.com/miss123/p/5517827.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!