Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

question  RSS feed

 
Soum Sark
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does
System.out.print("1")
compile when in a {} and not when outside. What purpose does the {} serve ?
class Q {
{
System.out.print("1");
}
static {
System.out.print("2");
}
Q() {
System.out.print("3");
}
}
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
{} denotes an instance initialization block. Please refer to JLS 8.6 Instance Initializers for detailed information.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!