This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes {} inside a method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "{} inside a method." Watch "{} inside a method." New topic
Author

{} inside a method.

Meg Adal
Ranch Hand

Joined: Mar 12, 2002
Posts: 70
I wrote following program,it compiles and runs fine.But I was expecting compilation error for {}
I am not able to undestand why does Java allows to have {} inside a method?
Is it treated as Instance Initializer block?
Jon Dornback
Ranch Hand

Joined: Apr 24, 2002
Posts: 137
it's perfectly legal to have a code block within a code block. i don't think it is commonly used, but the main effect is to limit the scope.
the code below shows an example of how it works:


use the [CODE] tags - it makes it much easier for people to help you.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Also, empty code blocks are perfectly legal, and occasionally useful (for instance, to act as placeholders for future code).


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Meg Adal
Ranch Hand

Joined: Mar 12, 2002
Posts: 70
Thanks All.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: {} inside a method.
 
Similar Threads
Reg. abstract class and method
static & nonstatic methods
Doubt in Integer and int
Shallow in static method ?
@Autowired not working in JUnit using spring 2.5