I have a silly question, I have two projects A and B. A is dependent on B. Both A and B have the same package named P. Why classes under project A and Project B in package P can use each other without import.
Because the Java compiler doesn't care how you organize your code. There is no concept of "Project" in Java, per se.
If the class is available on the classpath at compile-time and it is in the same package as the importing class, no import statement is necessary.
0
votes
The classloader doesn't care if classes are from different jar files or a single jar file, when it checks for other classes. Therefore no import is needed, if the classes are in the same package.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more