aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can Local Variables be declared as static ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can Local Variables be declared as static ?" Watch "Can Local Variables be declared as static ?" New topic
Author

Can Local Variables be declared as static ?

Puja S
Ranch Hand

Joined: Jan 06, 2005
Posts: 51
Thanks
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Local variables cannot be static, but they could be final.
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Static members belong to the class, no to the instance objects. Static members provide services to other classes and are accessed through by of the class to wich they belong. It would not make sense to declare a static variable in the context of a local method because it just could be accessed in the same context.
Serkan Yazici
Ranch Hand

Joined: Apr 24, 2004
Posts: 33
I think allowing static local variables in methods would have been a good idea. When you need the methods to remember their instance-independent state between calls.

I know, I know... you can still maintain this state information with static class variables but the idea is to have maximum encapsulation possible (if a member variable is only used to keep the state information about a single method, why expose it to the rest of the class).

I'm not too bothered about not having them though.


-- SCJP 1.4 (98%), SCJD (98%), SCWCD (96%), OCA Dev (97% avg.), SCBCD (97%), SCJP 1.5 BETA (90%)<br />-- OCP Dev (maybe), MCDBA (probably) SCEA (eventually)<br />-- Haven't tried Firefox yet? Free, open, secure, fast, tabified, and slick!<br />-- <a href="http://www.mozilla.org/products/firefox/" target="_blank" rel="nofollow">http://www.mozilla.org/products/firefox/</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can Local Variables be declared as static ?