I have a Java class:
Class A {
static Object a = new Object();
Object getObject() {
return a;
}
}
In above code. I want to ask when object a
is really initialized. I have two answers for my question:
When Java program is started. a will automatically initialize, although we will never use it.
the very first time we call getObject(). So, I think this will be more optimize.
I don't know which really true behind the scene.