File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Initialization sequence 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 "Initialization sequence" Watch "Initialization sequence" New topic

Initialization sequence

Asif Iqbal

Joined: May 02, 2008
Posts: 10
hi all!

Can anyone one explain me initailization sequence i.e. for

static variable
static block
static method
instance variable
instance block
instance method

and same for super class if we instansiate a subclass's object.
What can we use as Constroctor's body?

Sid Murrey
Ranch Hand

Joined: Jul 07, 2008
Posts: 58

When run, the following output is produced:

Local variables in static and non-static methods are of course only initialized when the method is called.
The order of execution of static blocks and static variable initialization is depending on the code, as far as I know!
[ July 23, 2008: Message edited by: Sid Murrey ]
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10033

The best way if for you to simply try it for yourself!

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Raphael Rabadan
Ranch Hand

Joined: Jul 05, 2008
Posts: 141

there is a interesting topic about it on the 2nd page, take a look at it:

SCJP Java 6 (98%) - Story, SCJA (88%) - Story
I agree. Here's the link:
subject: Initialization sequence
It's not a secret anymore!