• <small id='mXy1B'></small><noframes id='mXy1B'>

  • <i id='mXy1B'><tr id='mXy1B'><dt id='mXy1B'><q id='mXy1B'><span id='mXy1B'><b id='mXy1B'><form id='mXy1B'><ins id='mXy1B'></ins><ul id='mXy1B'></ul><sub id='mXy1B'></sub></form><legend id='mXy1B'></legend><bdo id='mXy1B'><pre id='mXy1B'><center id='mXy1B'></center></pre></bdo></b><th id='mXy1B'></th></span></q></dt></tr></i><div id='mXy1B'><tfoot id='mXy1B'></tfoot><dl id='mXy1B'><fieldset id='mXy1B'></fieldset></dl></div>

        <bdo id='mXy1B'></bdo><ul id='mXy1B'></ul>
    1. <legend id='mXy1B'><style id='mXy1B'><dir id='mXy1B'><q id='mXy1B'></q></dir></style></legend>

        <tfoot id='mXy1B'></tfoot>

        .java 文件中的包私有类 - 为什么它可以访问?

        时间:2023-09-27
        • <i id='JdiM6'><tr id='JdiM6'><dt id='JdiM6'><q id='JdiM6'><span id='JdiM6'><b id='JdiM6'><form id='JdiM6'><ins id='JdiM6'></ins><ul id='JdiM6'></ul><sub id='JdiM6'></sub></form><legend id='JdiM6'></legend><bdo id='JdiM6'><pre id='JdiM6'><center id='JdiM6'></center></pre></bdo></b><th id='JdiM6'></th></span></q></dt></tr></i><div id='JdiM6'><tfoot id='JdiM6'></tfoot><dl id='JdiM6'><fieldset id='JdiM6'></fieldset></dl></div>

          1. <tfoot id='JdiM6'></tfoot>

                <tbody id='JdiM6'></tbody>
            • <small id='JdiM6'></small><noframes id='JdiM6'>

                • <bdo id='JdiM6'></bdo><ul id='JdiM6'></ul>
                • <legend id='JdiM6'><style id='JdiM6'><dir id='JdiM6'><q id='JdiM6'></q></dir></style></legend>

                • 本文介绍了.java 文件中的包私有类 - 为什么它可以访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  考虑以下代码,其中 HelloWorld 类具有默认或包私有访问权限:

                  Consider the following code, where the HelloWorld class has default or package-private access:

                  class HelloWorld {
                      public static void main(String[] args) {
                          System.out.println("Hello World!"); // Display the string.
                      }
                  }
                  

                  并假设上述代码保存在一个名为HelloWorld.java 的文件中.所以我的问题是:既然 HelloWorld 现在是一个包私有类,它是如何工作的?main() 方法不应该跨包可见或可访问,对吗?

                  And assume that the above code is saved in a file called HelloWorld.java. So my question is: since HelloWorld is now a package-private class, how does it work? The main() method should not be visible or accessible across packages, am I right?

                  如果将类 HelloWorld 声明为 public,这对我来说非常有意义.只有在使用默认包私有访问声明时才会混淆.

                  It makes perfect sense to me if the class HelloWorld is declared public. Confusion is only when it is declared with the default package-private access.

                  推荐答案

                  JVM启动在§12.1 JLS 的虚拟机启动.

                  请注意,本章没有提及关于类的可见性检查.它only 指定main method 必须是public.

                  Note that this chapter says nothing about visibility checks with regards to the class. It only specifies that the main method must be public.

                  这意味着根本没有检查类级别的可见性(哪种类型有意义,因为还没有上下文可以检查可见性:在哪个包"中是调用者"?).

                  This means that there simply is no check for visibility on the class level (which kind-of makes sense as there is no context yet against which to check the visibility: in which "package" is the "caller"?).

                  这篇关于.java 文件中的包私有类 - 为什么它可以访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:R:无法安装 rJava;什么是 r-api-3.4? 下一篇:需要帮助在 Eclipse 中更改我的包名

                  相关文章

                  最新文章

                  <tfoot id='Ia07s'></tfoot>

                  <small id='Ia07s'></small><noframes id='Ia07s'>

                    <bdo id='Ia07s'></bdo><ul id='Ia07s'></ul>

                    <i id='Ia07s'><tr id='Ia07s'><dt id='Ia07s'><q id='Ia07s'><span id='Ia07s'><b id='Ia07s'><form id='Ia07s'><ins id='Ia07s'></ins><ul id='Ia07s'></ul><sub id='Ia07s'></sub></form><legend id='Ia07s'></legend><bdo id='Ia07s'><pre id='Ia07s'><center id='Ia07s'></center></pre></bdo></b><th id='Ia07s'></th></span></q></dt></tr></i><div id='Ia07s'><tfoot id='Ia07s'></tfoot><dl id='Ia07s'><fieldset id='Ia07s'></fieldset></dl></div>
                  1. <legend id='Ia07s'><style id='Ia07s'><dir id='Ia07s'><q id='Ia07s'></q></dir></style></legend>