Referring to the following code below, the out put is 5. I am showing the flow here with the numbers as I understood. When I debug this code using IntelliJ, I could not follow the flow. Can any body clarify me if am wrong of if I am missing any thing.
I have another question, new A(2) { {incY();} //... code skipped }; here how could the statements {incY();} compiled(though it does)? I understand only static method could be used this way, but it not declared as static, please enlighten me, thanks!
I assume you mean you know about static initializers. Instance initializers are there too, and the above is an example (does make you look twice though, doesn't it?).
Thank Steve, is this instance initializer on the SCJP objective list? As far as I can remember, it is not mentioned in both K&B and RHE which two books I have. [ September 19, 2003: Message edited by: Dep Joy ]
Right, I don't remember it mentioned in K&B, which is what I'm relying on, nor do I recall it popping up anywhere else but in this question. Might be a safe bet to ignore, but on the other hand, there's nothing to it. When a new instance is being initialized, after all its superclass initializations have completed: 1) its instance vars are initialized 2) any instance initializers are run 3) the constructor is run.
Right, I don't remember it mentioned in K&B, which is what I'm relying on, nor do I recall it popping up anywhere else but in this question. Might be a safe bet to ignore, but on the other hand, there's nothing to it. When a new instance is being initialized, after all its superclass initializations have completed: 1) its instance vars are initialized 2) any instance initializers are run 3) the constructor is run.
Hi Steve: I thought it was done in textual order. Following will give forward reference error: