This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
XinJi, If you dont specify a package for a class, then the class automatically gets put into a package called the "Default package", which is effectively an 'invisible' package. Just like other packages, the classes in the default package can access each others public methods and constructors. However, if you then have other classes that try to use classes in the default package which are not themselves in the default package, then you have to import them as shown in the post above. Jon
Joined: Jun 09, 2004
Sorry, the first sentance in the second paragraph is very clear. What I mean to say is that classes in the same package (including all those in the default package) do not have to use import declarations to access each other. As soon as you start using classes in other packages, you have to use import those classes at the top of the file before you can use them. Jon
Use of the default package is very strongly discouraged.
It used to be the case that you could import a class from the default package into a named package as shown, but it was never explicitly stated in the Java Language Spec that this was legal. Recent versions of the spec state that it is illegal, and recent versions of javac now reject this syntax. As a result, doing what you need to do is now not possible.