• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static variables and blocks

 
Rob Petterson
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me if static variables take priority over static blocks ie which one gets initialized first?
 
Guoqiao Sun
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, static variables and static blocks get initialized with the sequence they coded. No priority to each other.
regards,
Sun Guoqiao
Originally posted by Rob Petterson:
Can anyone tell me if static variables take priority over static blocks ie which one gets initialized first?
 
Rob Petterson
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guoqiao for clearing that up. I thought that was the case, but it's always good to get a second opinion.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guoqiao is correct. Member initalizers and initializer block are executed in textual order. This is the case for both instance initializers and static initializers.
Corey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic