aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes final variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "final variable" Watch "final variable" New topic
Author

final variable

Namit Puri
Ranch Hand

Joined: Aug 19, 2006
Posts: 51
public class Foo
{
static final int x = 12;

public void go(final int x)
{
System.out.println(x);
}
}

Why the above code is compiled successfully, even though the final int x variable is not initialized in the argument list of go method.
Java 5.0 says that a final variable should always be initialized.


Regards,
Namit Puri
SCJP 6.0
"Success is a journey, not a destination." Ben Sweetland
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19067
    
  40

The final local variable x, will be initialized with the first parameter value, when the method is called.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final variable