0

I am reading java certification book and here is the question from the book. Please have a look at the following directory structure shown in picture.

Directory Structure

Here is the source code for A.class and B.java

package xcom;
public class A{}

package xcom;
public class B extends A{}

Which allows B.java to compile.

  1. Set the current directory to test then invoke javac -classpath . xcom/B.java
  2. Set the current directory to test then invoke javac -classpath xcom B.java
  3. Set the current directory to test and then invoke javac -classpath xcom:. B.java

It says option 1 is correct and its actually compiling as well. My point is that basically in order for B.java to compile, it needs to find A.class. We are in directory test and when we say -classpath ., it searches for files in current directory. But A.class is not present in current directory. Can someone explain this concept to me?

Thanks, Ben

benz
  • 4,561
  • 7
  • 37
  • 68

1 Answers1

1

The period is telling it to search the current folder for the following path in this instance. Since you are setting the current directory to test and invoking -classpath . xcom/B.java it is like saying search this folder(the test folder) for xcom/B.java)

There are some similar questions such as this one: What is the effect of the dot (.) in the Java classpath?

Community
  • 1
  • 1
DoubleDouble
  • 1,493
  • 10
  • 25