作业-继承
實現如下類之間的繼承關系,并編寫Music類來測試這些類。
?
?
package T092201;public class Instrument {public void play(){System.out.println("彈奏樂器!");} }package T092201;public class Wind extends Instrument{public void play(){System.out.println("彈奏Wind!");}public void play2(){System.out.println("調用wind的play2");} }package T092201;public class Brass extends Instrument {//復寫play方法public void play(){System.out.println("彈奏brass!");}public void play2(){System.out.println("調用brass的play2!");} }package T092201;public class Music {public static void tune(Instrument i){i.play();}public static void main(String[] args){Wind w=new Wind();Brass b=new Brass();tune(w);tune(b);} }轉載于:https://www.cnblogs.com/wangguoning/p/5901486.html
總結
- 上一篇: 散记 ~ 2016-09-23
- 下一篇: linux个人常用命令备注