This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hide Local Variables

 
Ramneek Handa
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Have you heard about the "Hide Local Variables" in java.
This is somebody asked my in an interview.
Can you tell my anything about this.
Thanks for any help
 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you declare them inside of a method then you've basically 'hidden' them from class scope. You can also do the following

Hope this helps.
Sean
 
Ramneek Handa
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sean!
Is this the concept called Hiding local variables.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it isn't.
Hiding local variables is not allowed in java. If it would, you could write something like:

That is, the inner variable i "hides" the outer variable of the same name.
In Java, the above code gives a compile time error. On the other hand, local variable *can* hide member variables, as you probably know.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic