File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 19790
    
  20

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
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: access specifiers