• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final variable

 
carl chan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sharana sharana
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic