public class Child {
public Child() {
System.out.println("构造方法");
}
{
System.out.println("普通代码块");
}
static {
System.out.println("静态代码块");
}
public static void main(String[] args) {
new Child();
}
}
二:对于有子父类类继承关系
【父类的xxx ------> 子类的xxxx】
public class Father { //父类
public Father() {System.out.println("父类构造方法");}
{System.out.println("父类普通代码块"); }
static {System.out.println("父类静态代码块"); }
}
public class Child extends Father{ //子类
public Child() {System.out.println("子类构造方法");}
{System.out.println("子类普通代码块");}
static {System.out.println("子类静态代码块"); }
public static void main(String[] args) {
new Child();
}
}
三:有关变量的加载顺序
1、静态与非静态
静态的是随着类的加载而执行,普通的则是实例化的时候执行:
静态早于普通
谁先声明谁先执行:
静态变量与静态代码块谁先声明谁先执行;
普通变量与普通代码块谁先声明谁先执行;



