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
Jon Poulton
Greenhorn
Joined: Jun 09, 2004
Posts: 27
posted
0
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
I am replying because I am having this same problem in a much bigger application and I need help. So please if you have any input I thank you.
Donald Lee VonCannon Jr.
Greenhorn
Joined: Sep 15, 2004
Posts: 3
posted
0
actually the ^ mark should be right after the A like this:
import A; ^
Donald Lee VonCannon Jr.
Greenhorn
Joined: Sep 15, 2004
Posts: 3
posted
0
Ok, I can't get it to position it below the ; but that is where it is supposed to be. Try writing those file and compiling them yourselves. You should get the same error.
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.