Two Laptop Bag
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

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)

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.

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

Joined: Sep 28, 2004
Posts: 20524

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: final variable
It's not a secret anymore!