This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question" Watch "question" New topic
Author

question

Soum Sark
Ranch Hand

Joined: May 31, 2002
Posts: 50
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

Joined: Aug 26, 2001
Posts: 7610
{} denotes an instance initialization block. Please refer to JLS 8.6 Instance Initializers for detailed information.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
GeeCON Prague 2014
 
subject: question