The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Rajdeep Biswas wrote:
What is the problem in first?
I acknowledge your replies. Thanks.
Henry Wong wrote:Side Note: I have to admit that this is one of the handful of mistakes that I seem to have made more than once -- meaning I don't seem to learn from the mistake...
Static variables are initialized when the class is loaded. Instance variables are initialized when an instance is created. And every instinct tells you that the first always completes before the second -- and that during instantiation, you can assume that the static variables are all initialized. Of course, this is not true, as shown in this example.
Henry
The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Rajdeep Biswas wrote:and causes ExceptionInInitializerError (just a special case of NullPointerException)],
Almost at the brink of clearance of doubt. Is it going as follows?
When I am writing this
view plaincopy to clipboardprint?
public static ObjCreateDemo obj = new ObjCreateDemo();
then
1. instance block is executed [and causes ExceptionInInitializerError (just a special case of NullPointerException)],
2. constructor is called,
3. the reference is stored in "obj" variable.
gurpeet singh wrote:but regarding your order i would like to tell you when we do new ObjCreateDemo(), the compiler supplied no-arg constructor gets called , which calls super() i.e. object class constructor . after the Object class constructor executes the control return back to ObjCreateDemo constructor. After that instance initialization blocks are called , and after that rest of the statements in constructor gets executed
John Jai wrote:
gurpeet singh wrote:but regarding your order i would like to tell you when we do new ObjCreateDemo(), the compiler supplied no-arg constructor gets called , which calls super() i.e. object class constructor . after the Object class constructor executes the control return back to ObjCreateDemo constructor. After that instance initialization blocks are called , and after that rest of the statements in constructor gets executed
Gurpeet - You got the flow correct
gurpeet singh wrote:
Almost at the brink of clearance of doubt. Is it going as follows?
When I am writing this
view plaincopy to clipboardprint?
public static ObjCreateDemo obj = new ObjCreateDemo();
then
1. instance block is executed [and causes ExceptionInInitializerError (just a special case of NullPointerException)],
2. constructor is called,
3. the reference is stored in "obj" variable.
Frankly speaking im not able to get the answers. and i do not know whats the reason for the exception. but regarding your order i would like to tell you when we do new ObjCreateDemo(), the compiler supplied no-arg constructor gets called , which calls super() i.e. object class constructor . after the Object class constructor executes the control return back to ObjCreateDemo constructor. After that instance initialization blocks are called , and after that rest of the statements in constructor gets executed. Please henry would like you to clear our doubts and elaborate your answer ? And Raj if you know the answer now, please i would like an explanation from your side as well ?
Tell the difficulties that i am difficult.
Don't get me started about those stupid light bulbs. |