Java Enthuware模拟-20混乱-类路径和包
我正在使用enthuware来练习类路径和包的模拟问题。问题是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
//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?
给出的选项是
/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