public class MyClass
{
private static int x = getvalue();
private static int y =5;
public static void main(
String[] args)
{
System.out.println(x);
}
private static int getvalue(){
return y;
}
}
choices:
1)compiler error about access restriction on private variables of MyClass
2)compiler error about the forward referencing of getvalue method.
3)compiler error about the forward referencing of y static field
4)print 0
5) print 10.
Answer is 4) 0.
Please explain the output.Actually static fields are initialized when the class is loaded.in that case x value should be 5(since y is 5,got through getvalue()).Please explain the output.one more thing,Anyone please explain what is forward referencing concept.