This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes static initializers v static blocks. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "static initializers v static blocks." Watch "static initializers v static blocks." New topic

static initializers v static blocks.

Neil Mc
Ranch Hand

Joined: Oct 20, 2003
Posts: 32
Which is executed first when a class is loaded into the JVM... a static initializer statement or a static block..... or are they simply executed in the order in which they occur ?
Does the same apply to instance initializers and blocks ?
Also if we have a static variable with an initializer statement say...
static int i = 5;
Will i be initialized directly to 5 or will it first be initialized to its default value (0) and then have its initializer statement executed - giving it the value 5.
Thanks in advance - Neil.
I agree. Here's the link:
subject: static initializers v static blocks.
Similar Threads
Static Int and Methods
About instance in. and static initializer
Code within a curly braces
want to know the order of execution?
Static Blocks and Instance Initializers (on certification exam?)