8.1向上转型

package sedion.nsg.upcasting;

public enum Note {
	MIDDLE_C,C_SHARP,B_FLAT;
}

  

package sedion.nsg.upcasting;
public class Instrument {
	public void play(Note n){
		Syso.print("Instrument.play()");
	}
}

  

package sedion.nsg.upcasting;

public class Wind extends Instrument{
	public void play(Note n){
		Syso.print("Wind.play()");
	}
}

  

package sedion.nsg.upcasting;

public class Music {
	public static void tune (Instrument i){
		i.play(Note.MIDDLE_C);
	}
	public static void main(String[] args) {
		Wind flute = new Wind();
		tune(flute);
	}
}

  

posted @ 2014-01-08 19:50  子木聊出海  阅读(193)  评论(0编辑  收藏  举报