I believe I read in K&B that a package statement in a file applies to all classes in that file. As such, I am wondering why this doesn't compile:
Test class in file Test.java
Test2 class in file Test2.java
SameFile class in Test2.java
I would have thought the package statement in Test2.java applies to all classes in that file, as I said I'm quite sure I've read that in K&B. But instantiating the SameFile class doesn't work from class Test.
Am I missing something? Is it impossible to reference a class which is located in another file, if that class is not marked public (and its classname therefor does not match the name of the file) ?
I was intrigued by your example and made some further tests why the compiler needs class SameFile to be compiled in order to be found.
I tried to make SameFile pulbic(removed class Test2 too) and changed the file name to SameFile and now it compiles even if the class SameFile is not compiled.
I suppose that files that are used should be either compiled or public classes(still not compiled - source files) - but this is just my presumption(if someone can elaborate on the matter I would be really glad).
I think that it would be time consuming for the compiler to check all source files for the class that it is looking for. On the other hand, after compilation of Test2.java file, we get 2 class files and it is much easier for the compiler to find whatever it is looking for.