父類子類,static方法,構造函數 編譯調用的優先順序

package dd;

class Person {

 Person() {
  System.out.println("Person...");
 }

 // 隱式方法
 {
  System.out.println("Person hello...");
 }

 static {
  System.out.println("Person static...");
 }
}

 

public class Test extends Person {

 Test() {
  System.out.println("Test...");
 }

 {
  System.out.println("hello...");
 }

 static {
  System.out.println("static...");
 }

 public static void main(String[] args) {
  System.out.println("main...");
  new Test();
 }
}

 

 

// Person static...
// static...
// main...
// Person hello...
// Person...
// hello...
// Test...

// 編譯過程
// 1.父類靜態屬性
// 2.父類靜態方法體
// 3.子類靜態屬性
// 4.子類靜態方法體
// 5.父類非靜態屬性
// 6.父類非靜態:隱式方法
// 7.父類構造函數
// 8.子類非靜態屬性
// 9.子類非靜態:隱式方法
// 10.子類構造函數
// ================

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章