18 lines
384 B
Java
18 lines
384 B
Java
//: polymorphism/music/Music.java
|
|
// ©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
|
|
}
|
|
} /* Output:
|
|
Wind.play() MIDDLE_C
|
|
*///:~
|