This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes access specifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "access specifiers" Watch "access specifiers" New topic
Author

access specifiers

shivam aggarwal
Greenhorn

Joined: Oct 15, 2009
Posts: 8
local variables cannot have access specifiers.why?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11861
    
  18

Why would you need them? What do they do (in general), and how would that work in a method variable's case?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
Have you checked out Aspose?
 
subject: access specifiers
 
It's not a secret anymore!