what is happening in the compiler when we do forward referencing methods, how it will assign the value of another variable which is not declared. And we can use that inside methods. But why we cannot use the variable in static blocks. For example,
public class Forward {
static int i = test();
static int test() {
System.out.println(j);
j = 20;
return j;
}
static {
System.out.println(j);
j = 20;
}
static int j;
}
if we assign the value directly like, int i = j; int j = 10;
why this code is not compiling. How it is possible only with methods. How compiler compile the forward references internally. Is declaration happen first for all the variables and initialization happen next for all at a time or one by one. Explain it in detail.
Aucun commentaire:
Enregistrer un commentaire