explanation as to why instantiating the elements of an array of objects needs to be done inside a method
<p>Java beginner here who is terribly confused as to why </p>

<p>1) this is <strong>valid</strong>:</p>

<p></p>

<pre><code>public class MyArrayOfObjects {

    MyArrayOfObjects[] myArray = new MyArrayOfObjects[5];

    void InstantiateElements (){
        myArray[0] = new MyArrayOfObjects();
    }
}
</code></pre>

<p>2) while this is <strong>not</strong>:</p>

<p></p>

<pre><code>public class MyArrayOfObjects {

    MyArrayOfObjects[] myArray = new MyArrayOfObjects[5];

    myArray[0] = new MyArrayOfObjects();

}
</code></pre>

<p>from my understanding, each element of the array of objects is instantiating a MyArrayOfObjects object. So why does option 1 work while 2 does not?</p>
