Java class instance outside main method
<p>I am studying Java, and I am a beginner.
I tried to create three classes (in the same package).
One with main method (JavaApp1), another that I've called "JavaClass1" and the last class "JavaClass2".
Here's the JavaClass1's code:</p>

<pre><code>public class JavaClass1 {
public int var1;
public int var2;

}
</code></pre>

<p>JavaClass2's code:</p>

<pre><code>public class JavaClass2 {
JavaClass1 ogg = new JavaClass1();
ogg.var1 = 4;
ogg.var2 = 7;

}
</code></pre>

<p>In the JavaClass2, Netbeans show me two error, related to the assignments (JavaClass1.var1 and JavaClass.var2) "Package ogg does not exist.  expected.</p>

<p>But if i Create the Class instance and attributes assignments inside the main method, there are no problems. Why?</p>