This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Initialization sequence" Watch "Initialization sequence" New topic
Author

Initialization sequence

Asif Iqbal
Greenhorn

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

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

static variable
static block
static method
constructors
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?

thanks
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: 9351
    
    2

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
Hello,

there is a interesting topic about it on the 2nd page, take a look at it: http://www.coderanch.com/t/269520/java-programmer-SCJP/certification/initialization-sequence


SCJP Java 6 (98%) - Story, SCJA (88%) - Story
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Initialization sequence