码迷,mamicode.com
首页 > 其他好文 > 详细

编写Music类

时间:2016-05-23 00:37:20      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

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();
    }

}

技术分享

编写Music类

标签:

原文地址:http://www.cnblogs.com/wenwen123/p/5518341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!