I'm having trouble with this one too.
The other
thread linked above says "GetJar refers to "Foo.d" but does not either import myApp.* or refer to Foo.d by its fully qualified name. There is no way to get this code to compile." That is not the case in my book, or in the OP's (Original Poster). My book also has the following which uses the fully qualified name.
Furthermore, option "A" compiles the code fine on my machine, so long as the directory structure is preserved in the Jar file.
The jar can be created with after compiling the the
java file using
javac -classpath MyJar.jar GetJar.java
jar -cf myJar.jar myApp/Foo.class
However my issue is that the explanation for option C seems incorrect.
1st) there is no "MyJar.java" in option C. It should be "MyJar.jar"
2nd) even if it was written correctly I would take this to mean
java -classpath test/Myjar.jar GetJar
which is not the reason it would not work.
3rd) I think what it is trying to say is that the Jar file (MyJar.jar) does not include the GetJar.class file (which is in the
test directory).
A jar that contains this file can be created using the following command. This will allow option C to run and be correct as well. But it was not specifically said that these files were or were not in the Jar file.
jar -cf MyJar.jar GetJar.class myApp/Foo.class
or
jar -cf MyJar.jar *
So really C could also be correct, unless we assume that the only class in the Jar is myApp/Foo.class
perhaps giving the jar file creation command (and location executed) in place of the statement that "myApp/Foo.class is placed in a JAR file called MyJar.jar" would be much more clear.