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

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner class within a static method" Watch "Inner class within a static method" New topic

Inner class within a static method

Justyna Wozniak

Joined: Oct 04, 2006
Posts: 14
here's the code sample:

I do understand why an inner class within a static method has access to all static methods of the encapsulating class, but I don't understand why it also has access to all final authomatic variables within the encapsulating method (and no access to non-final authomatic variable in that method).
Does it also have any access to any other final variables in that class?

Thanks in advance,
Justyna W.
[ October 14, 2006: Message edited by: Barry Gaunt ]
James Quinton
Ranch Hand

Joined: Oct 02, 2006
Posts: 94
because our law said so.
refer to JLS 8.1.3
it clearly says:
method local variable not declared inside inner class must declared "final"
Santhosh Raje

Joined: Sep 26, 2006
Posts: 9
Since the final variable inside the method is a constant whose value is not going to be changed ,Hence even if there are multiple instances of Inner class objects the value of this variable is not going to be changed.
I agree. Here's the link:
subject: Inner class within a static method
jQuery in Action, 3rd edition