The fundamental idea with packages and classpath is that your classpath needs to be the parent directory of the top-most directory in your package.
If your package hierarchy is A.B.C:
Then, your classpath needs to be the parent directory of A.
Option A: The default classpath being /foo, your topmost package directory needs to be a subdirectory of foo. However, class A is in package xcom which is not in subdirectory foo, hence class A will not be found.
Option B: Using "classpath ." asks the
java compiler to look for class A in a subirectory of xcom (since the current directory is set to xcom). Since package xcom to which class A belongs cannot be a subdirectory of itself, class A cannot be found.
Option C: With the current directory test, the classpath . looks for class A in a subirectory of test, where package com exists and class A is found. You need to give the correct path to B.java here.
Option D: classpath xcom asks javac to look for class A in a subdirectory of xcom. This is similar to case B.
Option E: This would work, if the path to B.java is correct. javac looks for source files in the current directory which is set to test where class B cannot be found
[ January 25, 2007: Message edited by: Aniket Patil ]