2015-09-07 11:44:36 -06:00
|
|
|
|
// polymorphism/music/Music.java
|
2015-06-15 17:47:35 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
|
|
|
|
// Inheritance & upcasting.
|
|
|
|
|
package polymorphism.music;
|
|
|
|
|
|
|
|
|
|
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); // Upcasting
|
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
|
}
|
|
|
|
|
/* Output:
|
2015-06-15 17:47:35 -07:00
|
|
|
|
Wind.play() MIDDLE_C
|
2015-09-07 11:44:36 -06:00
|
|
|
|
*/
|