This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Array Initialization Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Array Initialization Doubt" Watch "Array Initialization Doubt" New topic

Array Initialization Doubt

Srividhya Kiran
Ranch Hand

Joined: Feb 17, 2008
Posts: 166

why am I getting compilation error at line 2 and not in line1. At line 2 I am getting an error saying can't assign a value to a final variable.

Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

Static means that the member variable is created and initialized when the class is loaded by the Java interpreter. Final means that the value cannot be changed after it is initialized. The static initialization block in line 1 is called when the class is loaded. The class has already been loaded by the timeLine 2 attempts to initialize the array in a method, and therefore is illegal to attempt to change the value of the final variable.

subject: Array Initialization Doubt