如果在java中同时存在构造代码块和非静态成员变量,请问他们的先后加载顺序?是顺序加载么?
例如:
public Test{
{
a =2.4f;
System.out.println("构造代码块");
}
float a =100;
public static void main(String[] args) {
System.out.println(new Test().a);
}
}
结果a = 100.0
public Test{
float a =100;
{
a =2.4f;
System.out.println("构造代码块");
}
public static void main(String[] args) {
System.out.println(new Test().a);
}
}
结果 a = 2.4 为什么呢?