permaculture playing cards*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "final variable" Watch "final variable" New topic
Author

final variable

carl chan
Ranch Hand

Joined: Mar 12, 2003
Posts: 42
1. If the final variable is not assigned a value at compile time then it is called a blank final variable.
2. All blank final static variables must be assigned in a static initializer.
3. All blank non-static variables must be assigned by the end of the instance construction process.
Can someone please explain 2 and 3 to me because I do not get it clearly. Thanks.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Originally posted by carl chan:
1. If the final variable is not assigned a value at compile time then it is called a blank final variable.
.

Yes.

Originally posted by carl chan:

2. All blank final static variables must be assigned in a static initializer.
.

It might be helpful to think of this case as follows. Static variables can be accessed after the class is loaded and even before any instance of the class is created. Therefore, it is obvious that the value of a blank final static variable must be assigned at load time using a static initializer.
Originally posted by carl chan:

3. All blank non-static variables must be assigned by the end of the instance construction process.

A non-static variable is associated with an instance of the class. The value of a blank non-static variable must be assigned before the instance creation process is complete. In other words, it must be assigned by the time the constructors runs to completion.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
sharana sharana
Greenhorn

Joined: Mar 14, 2003
Posts: 24
is it the right thing to say "
All blank non-static variables must be assigned by the end of the instance construction process??
the instance variables are not intialized to their defaults if not initialized explicitly
but same is not TRUE with blank final variables as they must Be intialized


sharana
 
Consider Paul's rocket mass heater.
 
subject: final variable