File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Final Var in Local Class. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Final Var in Local Class." Watch "Final Var in Local Class." New topic
Author

Final Var in Local Class.

Shah Chunky
Ranch Hand

Joined: Dec 27, 2000
Posts: 116
Hello all...
Final Var in Local Class.
Can someone tell me how in the below program can i access the
Final Variable x (See Comment Line 6)
class FinOuter
{
int w = 33;
void met()
{
final int w = 45;// Line 6
class Local
{
int w = 55;
void met()
{
System.out.println(w); // Prints 55
System.out.println(this.w); // Prints 55
System.out.println(FinOuter.this.w); // Prints 33
}
}
}
}
Thanks.

Shah Chunky - Sun Certified Java2 Programmer.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Once you define a "w" in the inner class you lose reference to the final "w" in the met() method.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Final Var in Local Class.
 
Similar Threads
mock eexamQ
Local Inner Class
Referenec passing
doubt Method local inner class
MethodLocalClass Question