Java Enthuware模拟-20混乱-类路径和包

Java Enthuware模拟-20混乱-类路径和包,java,classpath,Java,Classpath,我正在使用enthuware来练习类路径和包的模拟问题。问题是 //in file ./Foo.java public class Foo { public static void main(String[] args) { System.out.println("In Foo"); } } //in file ./com/Foo.java package com; public class Foo { public static void main(String[] a

我正在使用enthuware来练习类路径和包的模拟问题。问题是

//in file ./Foo.java
public class Foo {
  public static void main(String[] args) {
    System.out.println("In Foo");
  } 
}

//in file ./com/Foo.java
package com;
public class Foo {
  public static void main(String[] args) {
    System.out.println("In com.Foo");
  } 
}

Which of the given statements are correct assuming that the command lines are executed from the current directory with default classpath set to ./classes?
给出的选项是

  • 正在执行java-classpath.:./com-Foo将打印“In-com.Foo”
  • 正在执行java-classpath./com:。Foo将打印“在com.Foo中”
  • 执行JavaFoo将打印“In com.Foo”
  • java类路径。Foo将不会执行
  • 正在执行java-classpath./com:。com.Foo将打印“在com.Foo中”
  • 给出的正确选项是选项5。奇怪的问题是,当我试图从命令行执行选项5时,它会给我以下错误。

    有人能告诉我怎么了吗?我想不出原因。加上这是什么
    /com
    类路径是什么意思

    命令更改

    我注意到一件奇怪的事情,如果我更改类路径并按

    java -classpath . com.Foo
    
    java -classpath . com.Foo
    
    它在com.Foo中声明
    。只要我更改添加此路径的命令。/com。它给出了上述错误

    谢谢。

    “/com”是当前路径的相对路径

    如果您的类位于[current_path]/com/Foo.class中

    可以使用以下命令运行类:

     java -classpath ./com com.Foo
    
    如果您在com文件夹[current_path:com]/Foo.class中,则可以执行以下命令:

     java -classpath ./com com.Foo