1. 程式人生 > >類執行順序

類執行順序

ring images com mage log copyright 父類靜態 職責 ffffff

package com.solution; /** * demo 簡要描述 * <p> TODO:描述該類職責 </p> * * @author ckmike * @version 1.0 * @date 18-12-2 下午11:05 * @copyright ckmike **/ public class demo { public static void main(String[] args) { Parent son = new Son(); } } class Parent{ static { System.out.println("父類靜態代碼"); } public Parent(){ System.out.println("父類構造函數"); } } class Son extends Parent{ static { System.out.println("子類靜態代碼"); } public Son(){ super(); System.out.println("子類構造函數"); } }

技術分享圖片
備註:super()方法必須放置在構造函數第一行。

類執行順序