What is the explanation of this results in Java?
<p>I have the following code :</p>

<pre><code>public class Main {
    private int i = j; //1
    private int j = 10; 

    public static void main(String[] args) {
        System.out.println((new Main()).i);      
    }
}
</code></pre>

<p>and there is a compiler error in line 1 because an illegal
forward reference.<br/>
But when I am trying the following code :</p>

<pre><code>public class Main {
    int i = getJ();  //1

    int getJ(){
       return j;
    }
    int j=10;
    public static void main(String[] args) {
        System.out.println(new Main().i);
    }
}
</code></pre>

<p>it works fine and the result is 0.<br/>Why there is no illegal 
forward reference in line 1 here?.The two codes look similar to me.</p>
