It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static variables and blocks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static variables and blocks" Watch "static variables and blocks" New topic
Author

static variables and blocks

Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
Can anyone tell me if static variables take priority over static blocks ie which one gets initialized first?


Rob Petterson
SCJP
Guoqiao Sun
Ranch Hand

Joined: Jul 18, 2001
Posts: 317
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?


Guoqiao Sun<br />SCJP2 SCWCD2<br />Creator of <a href="http://www.jiris.com/" target="_blank" rel="nofollow">www.jiris.com</a>, Java resource, mock exam, forum
Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
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

Joined: Dec 20, 2001
Posts: 3271
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


SCJP Tipline, etc.
 
wood burning stoves
 
subject: static variables and blocks