File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Local Variable Scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Local Variable Scope" Watch "Local Variable Scope" New topic
Author

Local Variable Scope

Craig Oliver
Greenhorn

Joined: Aug 25, 2003
Posts: 21
From what I understand:
Local (method) variables can be declared anywhere in code of method.
They are then available for rest of method.

Question is:
If local variable is declared within try/catch exception block is scope of this variable only within try/catch block or entire method from then on?
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
You can refer to (�14.4.2) for more information about the scope of local variables.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Babar Qadri
Ranch Hand

Joined: Oct 12, 2004
Posts: 51
Only within try/catch block. And refer the link given by Vicken.
cheers.


babar
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
The key word is block.

Variables declared within a block { ... } are only known within that block.
The individual try, catch, and finally blocks are examples of this.


Mike Gershman
SCJP 1.4, SCWCD in process
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Local Variable Scope