File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Could not understand the output!

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 179
Hi, I came across this question in 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


Failure is not an option.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46352
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.
I agree. Here's the link:
subject: Could not understand the output!
It's not a secret anymore!