This is an example question from "SCJP mock exam":
Given the default classpath:
/foo
And this directory structure:
foo | test | xcom |--A.class |--B.java
And these two files:
package xcom; public class A { } package xcom; public class B extends A { }
Which allows B.java to compile? (Choose all that apply.)
A. Set the current directory to
xcom
then invokejavac B.java
B. Set the current directory to
xcom
then invokejavac -classpath . B.java
C. Set the current directory to test then invoke
javac -classpath . xcom/B.java
D. Set the current directory to test then invoke
javac -classpath xcom B.java
E. Set the current directory to test then invoke
javac -classpath xcom:. B.java
The answer is C, I don't understand the use of the operator .
there. Please explain.
The book says:
In order for
B.java
to compile, the compiler first needs to be able to findB.java
. Once it's foundB.java
, it needs to findA.class
. BecauseA.class
is in thexcom
package the compiler won't findA.class
if it's invoked from thexcom
directory. Remember that the-classpath
isn't looking forB.java
, it's looking for whatever classesB.java
needs (in this caseA.class
).
I don't get this, if both files are on the same package, why wouldn't the compiler find A?