From my home directory, I created a directory pkg and wrote 2 files A.java and B.java in it.
A.java
package pkg;
class A
{
B b;
}
B.java
package pkg;
class B
{
}
I went back to my home directory and typed the following :
javac -classpath . /pkg/A.java
It compiled correctly. My question is that A.java has a reference to class B. The compiler searches the classpath for any packages that contains class B. pkg being the only package in the classpath, it doesn't find the B class file there. It should have been the end of story and the code shouldn't have compiled. But what happens is that the B.java file is also compiled. Why ?