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!");
    }

}

结果:

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

posted @ 2016-08-04 23:06  TanMG  阅读(389)  评论(0编辑  收藏  举报