I understand the purpose of static keyword but regretfully I can't figure out this simple code. Don't know why? I'm expecting the answer to be really simple.
public class VariableScope {
int x=y;
static int y=5;
public static void main(String[] args) {
System.out.println(new VariableScope().x);
}
}
How x gets printed as 5 when y was assigned to it at an earlier stage?
staticassignment happens? Please enumerate explicitly what you expect to happen?