aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why only final variables can be accesed by local class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why only final variables can be accesed by local class" Watch "why only final variables can be accesed by local class" New topic
Author

why only final variables can be accesed by local class

sushant prabhu
Ranch Hand

Joined: Mar 22, 2001
Posts: 66
can someone explain the logic why only final variables can be accessed by a local class and not any non final variables of the method in which the class is declared


Sushant Prabhu<br />SCJP2<br />SCWCD<br />OCA9i
vinay jain
Greenhorn

Joined: Nov 07, 2001
Posts: 27
The reason for that is the life span of the objects. The local variables of the method are no longer available after the method finishes but for final variables compiler can generate the necessary code. The local class may exist a lot longer then the local method that's why the local class can't access the automatic variables.
Hope this helps.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why only final variables can be accesed by local class