• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

final variable

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic