<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### [名稱隱藏](https://lingcoder.gitee.io/onjava8/#/book/08-Reuse?id=%e5%90%8d%e7%a7%b0%e9%9a%90%e8%97%8f) 如果 Java 基類的方法名多次重載,則在派生類中重新定義該方法名不會隱藏任何基類版本。不管方法是在這個級別定義的,還是在基類中定義的,重載都會起作用: ~~~ // reuse/Hide.java // (c)2017 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. // Overloading a base-class method name in a derived // class does not hide the base-class versions class Homer { char doh(char c) { System.out.println("doh(char)"); return 'd'; } float doh(float f) { System.out.println("doh(float)"); return 1.0f; } } class Milhouse {} class Bart extends Homer { void doh(Milhouse m) { System.out.println("doh(Milhouse)"); } } public class Hide { public static void main(String[] args) { Bart b = new Bart(); b.doh(1); b.doh('x'); b.doh(1.0f); b.doh(new Milhouse()); } } /* Output: doh(float) doh(char) doh(float) doh(Milhouse) */ ~~~ **Homer**的所有重載方法在**Bart**中都是可用的,盡管**Bart**引入了一種新的重載方法。在下一章中你將看到,使用與基類中完全相同的簽名和返回類型覆蓋相同名稱的方法要常見得多。否則就會令人困惑。 你已經看到了Java 5 \*\*@Override \*\*注釋,它不是關鍵字,但是可以像使用關鍵字一樣使用它。當你打算重寫一個方法時,你可以選擇添加這個注釋,如果你不小心用了重載而不是重寫,編譯器會產生一個錯誤消息: ~~~ // reuse/Lisa.java // (c)2017 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. // {WillNotCompile} class Lisa extends Homer { @Override void doh(Milhouse m) { System.out.println("doh(Milhouse)"); } } ~~~ **{WillNotCompile}**標記將該文件排除在本書的**Gradle**構建之外,但是如果你手工編譯它,你將看到:方法不會覆蓋超類中的方法,**@Override**注釋防止你意外地重載。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看