Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could not understand the output!

 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic