Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scope of vars in a static block

 
P Teng
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. y is local to that block and could not be accessed outside.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic