Here is a code that I encountered while working on the Eclipse IDE.
class Demo
{
static
{
x = 100;
System.out.println(x);
}
public static void main(String args[])
{
//System.out.println(x);
}
static int x =1000;
}
Inside the static block, at the prin statement, it gives me an error "Cannot reference a field before it is defined", whereas, if I comment that, and uncomment the print statement inside main, it works fine. What seems to be the problem here?
