The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Initialization sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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: 8795

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


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Initialization sequence
 
Similar Threads
static block
Static method can only handle static variables but why is it still working in case of local variable
Inheritance & overriding problem
Need Help For Exam .
Initilization block