Difference between static declaration and non static declaration
<p>Static variables: Are the class variables and they are not created separately for each object of the class.<br>
Instance variables: Are also the class variables but are created for each object separately.<br>
The above definitions are just for references.  </p>

<p>Please explain why i am getting error in this class declaration.I know it is just because i have not of initialised x.</p>

<pre><code>class non_static{
public static void main(String args[])
{
int x;
System.out.println(x);

}
}
</code></pre>

<p>But this class declaration is totally fine.</p>

<pre><code>class static_example{
static int x;
public static void main(String args[])
{
System.out.println(x);
}

}
</code></pre>

<p>And output of this program is 0.  </p>

<p>Please do explain me why static member is initialized with the default value while local variables are not.</p>
