正在加载图片...
Thinking in Java 3 Edition // Compile-time constant int I =5: // static final / Cannot have method definitions void play(Note n)i// Automatically public String what ()i void adjust() public void p lements Instrument play(Note n)( printin("Wind. play()"+ n)i public String what()t return "wind"i 1 public void adjust()( class Percussion implements Instrument i public void play(Note n) System. out. println("Percussion. play () n); public String what ()t return "Percussion"i publ id adjust()i] class Stringed implements Instrument t public void play(Note n)t System. out. println("stringed play() public string what ()i return "Stringed"i j d adjust((] class Brass extends wind I public void play (Note n) t System. out. println("Brass. play() publ id adjust()i System. out. println("Brass. adjust ()")i class Woodwind extends wind i public void play(Note n)i System. out. println("Woodwind. play()+ n) public string what ()t return Woodwind"i j public class Musics t private static Test monitor new Test () Doesn't care about type, so new types / added to the system still work right static void tune(Instrument i)( 1. play(Note. MIDDLE_C) static void tuneAll(Instrument[] e) for(int i=0; i<elength; i++) 第4页共47页 www.wgqqh.com/shhgs/tij.html email:shhgs@sohu.comThinking in Java 3 rd Edition www.wgqqh.com/shhgs/tij.html email:shhgs@sohu.com ✄ 4 ☎ ✆ 47 ☎ // Compile-time constant: int I = 5; // static & final // Cannot have method definitions: void play(Note n); // Automatically public String what(); void adjust(); } class Wind implements Instrument { public void play(Note n) { System.out.println("Wind.play() " + n); } public String what() { return "Wind"; } public void adjust() {} } class Percussion implements Instrument { public void play(Note n) { System.out.println("Percussion.play() " + n); } public String what() { return "Percussion"; } public void adjust() {} } class Stringed implements Instrument { public void play(Note n) { System.out.println("Stringed.play() " + n); } public String what() { return "Stringed"; } public void adjust() {} } class Brass extends Wind { public void play(Note n) { System.out.println("Brass.play() " + n); } public void adjust() { System.out.println("Brass.adjust()"); } } class Woodwind extends Wind { public void play(Note n) { System.out.println("Woodwind.play() " + n); } public String what() { return "Woodwind"; } } public class Music5 { private static Test monitor = new Test(); // Doesn't care about type, so new types // added to the system still work right: static void tune(Instrument i) { // ... i.play(Note.MIDDLE_C); } static void tuneAll(Instrument[] e) { for(int i = 0; i < e.length; i++) tune(e[i]); }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有