This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Scope of vars in a static block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Scope of vars in a static block" Watch "Scope of vars in a static block" New topic
Author

Scope of vars in a static block

P Teng
Greenhorn

Joined: Nov 20, 2009
Posts: 16
Hi , a quick one please

The following code does not compile, complaining that it cannot find symbol : variable y.
Does this mean that variables in static or not static code blocks are limited in scope only to that block only if they have been declared there ?

Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Exactly. y is local to that block and could not be accessed outside.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Scope of vars in a static block