乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      父類 子類 構(gòu)造方法 初始化 執(zhí)行順序

       隱形的翅膀 2006-12-21
      如果子類構(gòu)造函數(shù)里沒有super,系統(tǒng)默認(rèn)super(),
      順序是先父類,后子類,對于每個(gè)類,都是先初始化,在調(diào)用構(gòu)造方法

      “父類的構(gòu)造方法調(diào)用發(fā)生在子類的變量初始化之前”。可以用下面的例子來證明:
      例一
      // Petstore.java
      class Animal {
          Animal() {
              System.out.println("Animal");
          }
      }
      class Cat extends Animal {
          Cat() {
              System.out.println("Cat");
          }
      }
      class Store {
          Store() {
              System.out.println("Store");
          }
      }
      public class Petstore extends Store{
          Cat cat = new Cat();
          Petstore() {
              System.out.println("Petstore");
          }
          public static void main(String[] args) {
              new Petstore();
          }
      }
      運(yùn)行這段代碼,它的執(zhí)行結(jié)果如下:

      Store
      Animal
      Cat
      Petstore
      例二
       

       class C {
          C() {
           System.out.print("C");
          }
       }
       class D {
           D() {
            System.out.print("D");
           }
        }
       
       class A {
          C c = new C();
          A() {
              this("A");
              System.out.print("A");
          }
          A(String s) {
              System.out.print(s);
          }
       }
       public class B extends A {
           D d= new D();
        B() {
      //        super("A->B");
              System.out.print("B");
          }
          public static void main(String[] args) {
              new B();
          }
       }
      打印是CAADB
      $處若執(zhí)行的話打印是CA->BDB

        本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多