In Q 3 on page 812 K&B,
Default classpath is : /foo
Directory structure is :
And these two files:
Which allows B.java to compile?
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
The answer says C is correct. But I think B should be correct.
Since class B extends A, to compile B.java compiler needs A.class
classpath is used only to search for .class files, not .java files. So in our example, we need classpath to get us to A.class
Based on these, Lets consider option B
We are in xcom directory
the classpath is "." , the current directory, "xcom" and A.class files is in xcom directory
And B.java is also in xcom directory
So B is correct.
In option C, we are in "test" directory.
the classpath is "." current directory "test" So classpath should have been "xcom" as A.class is in xcom
So C is incorrect.
Kindly explain... Thank you.