File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method local inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "method local inner class" Watch "method local inner class" New topic

method local inner class

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481
i thought final varaibles of enclosing class only accessible in method local inner class like method local variable(y1)
but i1 and i are accessing inside inner class.Why?
marc weber

Joined: Aug 31, 2004
Posts: 11343

It's only the non-final local (method) variables that the local class cannot use. The reason is that local (method) variables are destroyed when the method exits. If these are final, then their values can be copied into any instances of the local class.

But the local class can use non-final variables outside the method (that is, members of the enclosing class).

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: method local inner class
It's not a secret anymore!