<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 功能強大 支持多語言、二開方便! 廣告
                ## 繼承 課堂代碼: ~~~java package com.dodoke.demo; public class Animal { protected String sex; protected int age; protected String color; protected String type; public void eatFood() { System.out.println(this.type + " is eating food"); } protected String sleep() { return this.type + " 正在睡覺"; } public Animal() { } public Animal(String type, int age) { this.type = type; this.age = age; } public Animal(String sex, int age, String color, String type) { super(); this.sex = sex; this.age = age; this.color = color; this.type = type; } } ~~~ ~~~Java package com.dodoke.demo; public class Dog extends Animal { private String bark; public String getBark() { return this.bark; } public void setBark(String bark) { this.bark = bark; } //繼承語法 /** * [修飾符] class SubClass extends SuperClass { * 修飾符 class 子類名稱 extends 父類名稱 * } */ /** * 重寫實際上針對父類的方法進行修改 * 通常會在重寫的方法上加上注解 @Override * @param args */ @Override public String sleep() { return this.type + "正在躺著睡覺"; } /** * 重寫的toString()方法 * 會在打印對象的時候,主動調用toString()方法,打印對象信息 */ @Override public String toString() { return "Dog [type = "+ this.type + ",age = "+ this.age +",color = "+ this.color +",sex = "+ this.sex +",bark = "+ this.bark +"]"; } /** * 使用super可以調用父類被覆蓋的方法和父類的屬性 */ public void getFatherMethodSleep() { System.out.println(super.sleep()); eatFood(); } /** * 調用父類構造器 * [修飾符] 類名() { * super();//在第一行調用父類構造器 * } */ public Dog() { super(); } public Dog(String type, int age) { super(); this.type = type; this.age = age; }; public Dog(String type, int age, String color) { super(type,age);//調用了父類的構造器,注意!!! //this(type,age);在同一構造器中,this()和super()只能出現一個 this.color = color; } public Dog(String sex, int age, String color, String type, String bark) { super(sex, age, color, type); this.bark = bark; } public static void main(String[] args) { Dog dog = new Dog(); dog.type = "狗 "; dog.age = 9; dog.color = "黑色"; dog.sex = "公"; dog.setBark("ww"); dog.eatFood(); System.out.println(dog.sleep()); dog.getFatherMethodSleep(); System.out.println(dog); Dog dog2 = new Dog("狗", 7, "白色"); System.out.println(dog2); } } ~~~
                  <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>

                              哎呀哎呀视频在线观看