The following program gives compilation error:
Temp.java:22: illegal forward reference
static int j = t3*getValue(100);
^
1 error
I understand because "t3" is yet not defined. So compiler doesn't yet know about "t3".
However, if I change it to "static int j = getValue(100); //line 22" then it works fine and output
is "j = 101 t3 = 5"
How come compiler is happy for this? How the compiler knows about "t3", which is used
in getValue(int) method because I thought that statics are intialized/defined in the textual order.
Could anybody throw some light on this?
Thanks,
Deep
public class Temp {
Temp() {
System.out.println("j = " + j + " t3 = " + t3);
}
public static void main (
String args[]) {
Temp t = new Temp();
}
private static int getValue(int i) {
System.out.println("getValue " + i);
return ++i+t3;
}
static int j = t3*getValue(100);
static int t3 = 5;
}