开发者

accessing protected properties from java subpackages

suppose I have package J

moreover I create a new folder in J hence it becomes a subpackage of J, let's say i开发者_JAVA技巧t's J.E

suppose I have a class in J named H with protected properties, and another class named T in J.E

can class T access the protected properties of H?


Sub-packages are useful only as an organizational concept. They can never be used for access control; no access relationships exist between a parent package and a child package.

From the Java Language Specification:

7.1 Package Members

...

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. 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.

In the context of your problem, class T cannot access the protected properties of H unless T is a subclass of H.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜