This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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
Author

Inner class within a static method

Justyna Wozniak
Greenhorn

Joined: Oct 04, 2006
Posts: 14
Hello,
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
Greenhorn

Joined: Sep 26, 2006
Posts: 9
Hey,
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: http://aspose.com/file-tools
 
subject: Inner class within a static method
 
Similar Threads
Inner class and Methods
innerclass
Inner class basics. (Marcus Green's mock exam 2)
regarding non-static inner class
Why can't a top-level class use the static keyword?