• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static block vs. Static initialization

 
Jim Crawford
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I don't understand the bold bit. Code in a static block will not be executed per creation / instantiation according to me.
Am I missing something?
Originally posted by Sam Wong:
[QB]You are correct in the sequence. You may be confused by the use of word "constructed" in the tip. If I reword the tip to be:
Instance initializer(s) gets executed ONLY IF new is called.
So if an object is created via new, then instance initialization and then constructors are executed. Note that static member initialization is done once when the class is loaded. So repeated instance creation will not perform static initialization. However, code residing within a static block will get executed per creation. So be careful with it.
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given that the output from
is SIII, I have to agree. Perhaps the author typo'd the static part?
[ January 14, 2004: Message edited by: Ray Stojonic ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic