Jim Hoglund wrote:One use is to hold code that you want to run immediately when the class is loaded,
before any objects are instantiated. For an inheritance tree, this means that the
order of execution of the static blocks is from subclass on up. (Execution of any
non-static blocks is from superclass on down.) How is this useful? I'd just say,
very special situations.
Jim ... ...
Abimaran Kugathasan wrote:
Zhiwei Huang wrote:
my bad. the static flag is set to 0 instead of 9 when initialized.
Thus as d is static, the two threads are calling the same chat method on same instance, as the explanation on K&B's book says, they cannot swap back and forth... so the answer should be only F...
This is NOT fair. When I answered the question, the variable flag is set to 9. You've changed it to 0. If it is 9, the possible answer are E and E.
Because, now it is 9, the only answer is F.
When you EDIT the code, after some one has answered, it's better to put the reason to EDIT, otherwise it'll be ODD.
Abimaran Kugathasan wrote:Welcome to JavaRanch! QuoteYourSources when you ask question.
E, F are the correct answer. Remember in DudesChat class you have a static variable d. So think about that.
Got it? If not ask!