Ramesh Sahu wrote: (In Duplicate Thread)
Thanks for your reply.
But I really want to know what happens when the static block calls any static function with assignments within it &
when main method calls up the static method ......
I actually what to know what happens to assignments??
I am a bit confused!!!
> what happens when the static block calls any static function with assignments within it
The static block calls the static function, and the static function makes its assignments. Then, when the static block comes to an end the next line of code is executed.
> (what happens) when main method calls up the static method
The same thing that happens when any method calls up a static method. If the class whose method is being called hasn't been initialized yet, then run through the static initialization processes. Then, once that is done, execute the code in the static method. Then continue on with the next line of code.
> I actually what to know what happens to assignments?
They occur in the order in which they are reached. In your example, the order they occur in is:
1) sum = 1 (code line 22. in original post, traced back to line 05.[static block])
2) initialized = true (code line 23. in original post, traced back to line 05.[static block])
3) initialized = false (code line 16. in original post)
4) sum = 2 (code line 22. in original post, traced back to line 12.[getSum()] from line 33.[main()])
5) initialized = true (code line 23. in original post, traced back to line 12.[getSum()] from line 33.[main()])