Might be a silly question, but when is the static variable initialized(so it occupies memory) while the program is running?
public class TestStaicInitilization {
int i;
public static final TestStaicInitilization test = new TestStaicInitilization();
TestStaicInitilization(){
this.i = 10;
}
public static void main(String[] args) {
System.out.println(TestStaicInitilization.test.i);
}
}
the output is: 10
Is the TestStaicInitilization.test
initialized while loading the class itself or when it is first accessed?