File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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: 9345
    
    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
 
 
subject: Initialization sequence
 
Similar Threads
Need Help For Exam .
Initilization block
static block
Inheritance & overriding problem
Static method can only handle static variables but why is it still working in case of local variable