Codeninja
Codeninja

Reputation: 55

Why the classpath in A does not compile?

I am learning classpaths and how to insert package files in a classpath, I am having a problem in understanding this example. Here it is :

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?

A. Set the current directory to xcom then invoke javac -classpath . B.java

B. Set the current directory to test then invoke javac -classpath . xcom/B.java

Only B compiles, my question is why doesn't A compile ? if we set current directory to xcom ,then since A.class is present in xcom , A should also work fine , but it doesn't, why is it so?

Thanks in advance

Upvotes: 0

Views: 38

Answers (1)

Andy Turner
Andy Turner

Reputation: 140484

Because it's looking for the package xcom as a subdirectory of xcom.

Set the classpath to .., and option A works.

Upvotes: 1

Related Questions