Forums Register Login

final variable

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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
Get out of my mind! Look! A tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 558 times.
Similar Threads
Exam 7, Q18 Dan Chisholm
javaprogramming
rules roundup & general question
Dan's question about declarations and access control
Dan's Mock: Field declaration Q 7
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:58:45.