It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes local inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "local inner class" Watch "local inner class" New topic

local inner class

Anne Sullivan

Joined: Mar 29, 2007
Posts: 9
Does a local inner class which resides inside a static method still have the "can only access local variables that is declared final" restriction?
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
yes whether the class is declared in a static or a non static method, it can only access local variables that are marked final..

when you compile this code it gives an error like:: local variable b is accessed from within inner class; needs to be declared final
System.out.println("b = " + b);
1 error

"History would be kind to me, for I intend to write it."
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Someone deleted my reply

I agree. Here's the link:
subject: local inner class
It's not a secret anymore!