posted 16 years ago
Hi,
I have one doubt regarding the Static Initiliser block, and the variable declared in that block.
I have 2 different scenario:
1)
static{
static int x = 999;
System.out.println("x:"+x);
}
2)
static int x;
static{
int x = 999;
System.out.println("x:"+x);
}
The Scenario 1 gives the compile time error, while scenario 2 not.
In the first Scenario we are declaring the static variable inside the Static block, while in the second one we are declaring the static variable outside the Static block and using them.
Why we can't declare the static variable inside static block.
What might be the problem?