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

  

你可能感兴趣的:(转)