• Post Reply Bookmark Topic Watch Topic
  • New Topic

local variable  RSS feed

 
Shalini Srivastav
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I thought it wont compile since x is local variable declared in case 1 but it is being access in case 2 without any problem ,sounds strange.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the variable scope of a case apply to remaining statement in switch unless you restrict them using braces.
 
Shalini Srivastav
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh,that's great.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can work that one out if you check the rules about scope.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!