java找不到或无法加载主类?

参考书籍:thinking in java第四版 P149 一个简单的多态
package polymorphism.music;

package polymorphism.music;

enum Note {
    MIDDLE_C, C_SHARP, B_FLAT; // Etc.
} ///:
package polymorphism.music;
import static net.mindview.util.Print.*;

class Instrument {
  public void play(Note n) {
    print("Instrument.play()");
  }
}
package polymorphism.music;

// Wind objects are instruments
// because they have the same interface:
class Wind extends Instrument {
  // Redefine interface method:
  public void play(Note n) {
    System.out.println("Wind.play() " + n);
  }
} ///:~
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
*///:~

就是一个简单的多态,其中这几个类文件在同一个目录下。不过我在command line下编译时 编译通过 却提示无法找到或加载类文件

clipboard.png
我在Eclipse下,顺利地跑起来了。
求解,这是为何?

阅读 12k
4 个回答

你应该在D:\Code\TIJ4-code>下执行

shelljavac polymorphism/music/*.java
java polymorphism.music.Music

你只用javac编译了Music类,没有编译其他的类

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题