gpt4 book ai didi

java - Java 是否提供了一种方法来允许从层次结构中的包进行特殊访问?

转载 作者:行者123 更新时间:2023-11-30 07:17:51 25 4
gpt4 key购买 nike

Java包层级会影响类和变量的访问权限吗?

关于 Java 包:http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

请看这一行:

... The second column indicates whether classes in the same package as the class (regardless of their parentage) have access to the member. ...

据我所知,package com.googlepackage com.google.music 是两个独立的包。他们完全没有联系。它们的区别就像package com.googlepackage com.yahoo 之间的区别一样。

这是真的吗?

有没有办法或关键字(public、private、protected 等)可以建立package com.googlepackage com.google.music< 之间的关系 更近?

谢谢!

最佳答案

Java 语言规范 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.

也就是说,您如何嵌套包对程序的语义没有影响。

关于java - Java 是否提供了一种方法来允许从层次结构中的包进行特殊访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15772693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com