Does Java Package hierarchy affect the access right of classes and variables?
About Java Package: http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
Please take a look at this line:
... The second column indicates whether classes in the same package as the class (regardless of their parentage) have access to the member. ...
As far as i know, package com.google
and package com.google.music
are two separate packages. They have absolutely no connections. Their differences are just like the differences between package com.google
and package com.yahoo
.
Is this true?
Is there a way, or a keyword (public, private, protected, etc.), which can make the relations between package com.google
and package com.google.music
closer?
Thanks!
The Java Language Specification writes:
The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level type (§7.6) declared in that package.
For example, there is no special access relationship between a package named oliver and another package named oliver.twist, or between packages named evelyn.wood and evelyn.waugh. That is, the code in a package named oliver.twist has no better access to the types declared within package oliver than code in any other package.
That is, how you nest your packages has no effect on the semantics of a program.