Simple Java "New" concept question
<p>The compiler shows an error at <code>new Stock[2];</code> after <code>;{</code> expect.</p>

<pre><code>public class TestStockUI {
    Stock[] stock = new Stock[2];
    stock[0] = new Stock("Microsoft", "MSFT", 15.69);
    stock[1] = new Stock("Google", "GOGL", 323.98);

    public TestStockUI() { }

}
</code></pre>

<p>Then I have changed it like below resulting in the same error.</p>

<pre><code>public class TestStockUI {
    Stock[] stock = new Stock[2];
    stock[0] = new Stock("Microsoft", "MSFT", 15.69);
    stock[1] = new Stock("Google", "GOGL", 323.98);

}
</code></pre>

<p>This solve the problem but I don't know why.</p>

<pre><code>public class TestStockUI {
    Stock[] stock = new Stock[2];
    {
        stock[0]=new Stock("Microsoft","MSFT",15.69);
        stock[1]=new Stock("Google","GOGL",323.98);
    }

}
</code></pre>
