Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final variable

 
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
Marshal
Pie
Posts: 20997
76
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic