Java繼承結構中類的初始化

來源:互聯網
上載者:User

    初學者測試

    昨天自考考了《java程式語言設計》,有點不太記得類的初始化過程了,順便複習了一下。

    同樣準備了測試題一枚。把自己的email分散到輸出中,如果正確輸出,說明分析正確了。

    不行怎麼行,這是基礎。下面程式請先分析,如果結果(用白色字型是輸出結果)正確,說明您對java類的初始化已經很熟悉,算是過關,如果沒有,那趕緊複習吧。

 

package nie.test.extend;  /** 子構造子的初始化過程:  * @author dotjar  *  1.父static域  *  2.父static塊  *  3.子static域  *  4.子static塊  *  5.父普通域 *  6.父普通塊{}  *  7.父構造子  *  8.子普通域 *  9.子普通塊{}  *  10.子構造子  */  public class Test {      public static void main(String[] args) {          new Son("s");      }  }  class Father {      static protected String s = "father_static_property_string";  //1    protected String b = "father_normal_property_string";  //5    static {          s = "o";  //2        System.out.print("d");          System.out.print(s);      }      {          b="r";  //6        System.out.print("a");          System.out.print(b);      }      Father() {          this("@");          System.out.print("1");  //8    }      Father(String s) {          System.out.print(s);  //7    }  }  class Son extends Father {  public static String s = "son_static_property_string"; //3public String b = "son_normal_property_string"; //9    static {          s = "j";  //4        System.out.print("t");          System.out.print(s);      }      {          b = "3";  //10        System.out.print("6");          System.out.print(b);      }      Son() {          System.out.print(".");  //11    }      Son(String s) {          this();          System.out.print("com");  //12    }  }  

 

 測試完自己的輸出,可以用滑鼠選中下一行,檢查。

這裡:dotjar@163.com

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.