• Post Reply Bookmark Topic Watch Topic
  • New Topic

final variable  RSS feed

 
Namit Puri
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Sheriff
Posts: 23280
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The final local variable x, will be initialized with the first parameter value, when the method is called.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!