File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method local inner class

 
Shiva Mohan
Ranch Hand
Posts: 484
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic