Java基礎之static default 構造函數!

package ssh;

public class father {
    
    public father() {
        System.out.println("father!");
    }
    
    {
        System.out.println("father default!");
    }
    
    static {
        System.out.println("father static!");
    }

}

package ssh;

public class son extends father{
    
    public son(){
        System.out.println("son!");
    }
    
    {
        System.out.println("son default!");
    }
    
    static {
        System.out.println("son static!");
    }
    
    public static void main(String[] agrs) {
        System.out.println("start!");
        new son();
        System.out.println("middle!");
        new son();
        System.out.println("end!");
    }

}

結果:ssh

father static!
son static!
start!
father default!
father!
son default!
son!
middle!
father default!
father!
son default!
son!
end!spa

相關文章
相關標籤/搜索