Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access specifiers

 
shivam aggarwal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
local variables cannot have access specifiers.why?
 
Rob Spoor
Sheriff
Pie
Posts: 20497
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because access modifiers are for allowing and disallowing code from other classes to access fields, methods etc. Local variables are valid only for the duration of the method, so other classes could not access them anyway - once they get to try the variable has already gone out of scope.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12090
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you need them? What do they do (in general), and how would that work in a method variable's case?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic