File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Could not understand the output! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Could not understand the output!" Watch "Could not understand the output!" New topic
Author

Could not understand the output!

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
Hi, I came across this question in SkillAssert.com which is a mock test in our forum itself



The output is
In getStr
In static
In Main

But i thought that static initialization blocks run first. Can anyone please explain?
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Static initializer and static block runs in the order they have been declared.

Since static initalizer is declared before static block it gets run first and then continues the static block.

Note: order not only matters for block but also including initializers like the one in the above program


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
I think you are correct, but have not used the usual terminology.That is a static declaration and initialization, which calls a static method.
What is next is a static initializer.
 
jQuery in Action, 2nd edition
 
subject: Could not understand the output!