wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 19651
    
  18

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: 11153
    
  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
 
Similar Threads
basic question on access modifiers and levels
access specifier and access modifier
Constructors
Access specifiers & Access Modifiers
database in netbeans