我对以下代码有点困惑:
public class Test{
int x = giveH();
int h = 29;
public int giveH(){
return h;
}
public static void main(String args[])
{
Test t = new Test();
System.out.print(t.x + " ");
System.out.print(t.h);
}
}
Run Code Online (Sandbox Code Playgroud)
这里的输出是0 29,但我认为这必须是一个编译器错误,因为当涉及到该方法时,变量h应该尚未初始化giveH().那么,编译是从上到下进行的?这为什么有效?为什么值为x0而不是29?