I encountered a question that asks \"Which of the following are true about the \"default\" constructor?\"
and an option \"It initializes the instance members of the cla
In Java fields are initialized before the constructor. This can be easily proved by the following code:
public class MyClass {
int myField = initMyField();
MyClass(){
System.out.println("ctor");
}
static int initMyField() {
System.out.println("init field");
return 1;
}
}
output
init field
ctor
You can also check the de-compiled code.