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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 基礎程序題 **題目一** ~~~ class Base{} class Agg extends Base{ public String getFields(){ String name = "Agg"; return name; } } public class Avf{ pulic static void main(String argv[]){ Base a = new Agg(); //here } } ~~~ 下面哪個選項的代碼替換到//here會調用getFields方法,使出書結果是Agg ~~~ A. System.out.println(a.getFields()); B. System.out.println(a.name); C. System.out.println((Base)a.getFields()); D. System.out.println(((Agg)a).getFields()); ~~~ 答案 D Base 類要引用 Agg 類的實例需要把 Base 類顯示地轉換成 Agg 類,然后調用 Agg 類中的方法. 如果 a 是 Base 類的一個實例,是不存在這個方法的,必須把 a 轉換成 Agg 的一個實例 **題目二** ~~~ class A{ public A(){ System.out.println("A"); } } public class B extends A{ public B(){ System.out.println("B"); } public static void main(String[] args){ A a = new B(); a = new A(); } } ~~~ 輸出結果是 A B A **題目三** ~~~ class A{ public void print(){ System.out.println("A"); } } class B extends A{ public void print(){ System.out.println("B"); } } public class Test{ .. B objectB = new B(); objectB.print(); A as = (A) objectB; as.print(); A asg = objectB; asg.print(); as = new A(); as.print(); .. } ~~~ 輸出為 B B B A **題目四** ~~~ public class Test { public static void main(String[] args){ Father father = new Father(); Father child = new Child(); System.out.println(father.getName()); System.out.println(child.getName()); } } class Father{ public static String getName(){ return "Father"; } } class Child extends Father{ public static String getName(){ return "Child"; } } ~~~ 輸出是 Father Father 因為這里的方法 getName 是靜態的. 具體執行哪一個,則要看是由哪個類來調用的.
                  <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>

                              哎呀哎呀视频在线观看