Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

access specifiers  RSS feed

 
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
Posts: 21092
85
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: 12542
48
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
Boost this thread!