2015-04-20 15:36:01 -07:00
|
|
|
|
//: polymorphism/music/Music.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-20 15:36:01 -07:00
|
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
} /* Output:
|
|
|
|
|
Wind.play() MIDDLE_C
|
|
|
|
|
*///:~
|