Does importing of packages change visibility of classes?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-03-07T21:33:28Z Indexed on 2010/03/11 4:55 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

I jsut learned that

A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package.

This is a clear statement. But this information interfere with my understanding of importing of packages (which easily can be wrong). I thought that importing a package I make classes from the imported package visible to the importing class.

So, how does it work? Are public classes visible to all classes everywhere under condition that the package containing the public class is imported? Or there is not such a condition? What about the package-private classes? They are invisible no mater if the containing package was imported or not?

ADDED: It seems to me that I got 2 answers which are marked as good (up-voted) and which contradict eachother.

© Stack Overflow or respective owner

Related posts about java

Related posts about private