public class ShadowTest
{
public int x = 0;
class FirstLevel
{
{ // here not able to understand why it allows.
x = 1;
}
void methodInFirstLevel()
{
System.out.println("x = " + x);
// System.out.println("this.x = " + this.x);
System.out.println("ShadowTest.this.x = " + ShadowTest.this.x);
}
}
public static void main(String... args)
{
ShadowTest st = new ShadowTest();
ShadowTest.FirstLevel fl = st.new FirstLevel();
fl.methodInFirstLevel();
}
}
I'm not clear why, without brackets, it doesn't work and what the significance of the brackets is? Please explain in detail.