Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

method local inner class

 
Shiva Mohan
Ranch Hand
Posts: 486
  • 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
  • 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).
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!