有两个类Parent son
public class Parent {
{
System.out.println("父类构造块");
}
static{
System.out.println("父类静态构造快");
}
public Parent(){
System.out.println("父类构造方法");
}
}
public class son extends Parent {
{
System.out.println("类构造块");
}
static{
System.out.println("类静态构造快");
}
public son(){
System.out.println("类构造方法");
}
}测试运行结果为
public class ArrayListTest {
public static void main(String[] args) {
Parent p = new son();
/*
父类静态构造快
类静态构造快
父类构造块
父类构造方法
类构造块
类构造方法
*/
}
}
总来的说,先父类,后子类。静态优先加载,构造方法初始化之前会优先加载类中构造代码快,本文出自 “龙光祥的blog” 博客,请务必保留此出处http://18073491002lgx.blog.51cto.com/12044386/1879315
原文:http://18073491002lgx.blog.51cto.com/12044386/1879315