default classpath /foo
foo ->
test -> xcom -> A.class
-> B.java
Two files :
package xcom;
public class A {}
package xcom;
public class B extends A {}
Which allows B.java to compile?
1. set the current directory to xcom then invoke
javac B.java
B. set the current directory to xcom then invoke
javac -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
This question is from K&B.
The Answer is C.
While running A and B - I got " Cannot find symbol A ie. public class B extends A "
And running D and E - I got " Cannot read B.java"
Can somone tell me what differnece does the Classpath make for a file with a package and for a file with Out a package.
If a file did not have a package , I would simply run the file MyFile.java from the current directory which is set in my classpath
Classpath = C:\classfiles;
C:\Classfiles> javac MyFile.java If both the files are located in xcom , why can't we invoke the command from xcom rather then Test.
C. set the current directory to test then invoke
javac -classpath . xcom/B.java It says that the classpath is set to the current directory which is Test.
Then how come it finds the A.class file which is present in xcom and not in Test.
Can some one please clear out the relation between classpath and Packages.
Thanks...