弹奏乐器

实现如下类之间的继承关系,并编写Music类来测试这些类。

 1 package aaa;
 2 
 3 class Instrument {
 4     public void play () {
 5         System.out.println("弹奏乐器:");
 6     }
 7 }
 8 
 9 class Wind extends Instrument {
10     public void play () {
11         System.out.println("弹奏Wind");
12     }
13     public void play2 (){
14         System.out.println("调用wind的play2");
15     }
16 
17 }
18 
19 class Brass extends Instrument {
20     public void play () {
21         System.out.println("弹奏Brass");
22     }
23     public void play2 () {
24         System.out.println("调用brass的play2");
25     }
26 
27 }
28 
29 
30 
31 public class Music {
32     public static void tune (Instrument i) {
33         i.play();
34     }
35 
36     public static void main(String[] args) {
37         Music mm = new Music();
38         Instrument dd = new Instrument();
39         Wind bb = new Wind();
40         Brass cc = new Brass();
41         tune (dd);
42         tune (bb);
43         tune (cc);
44         
45     }
46 }

 

posted @ 2019-05-05 11:53  孙贤超  阅读(203)  评论(0编辑  收藏  举报