Forums Register Login

Using final

+Pie Number of slices to send: Send
Hi.,
my doubt is about final keyword.,

i think a variable whether it is primitive or reference variable ., when it is declared as final variable we can't modify that value.,

but can we assign a final reference variable of an object to another reference variable of the same class?
+Pie Number of slices to send: Send
Final in combination with a primitive means that it's value can never change.
Final in combination with a reference means that the reference can never change.
+Pie Number of slices to send: Send
 

r suraaj wrote:Hi.,
my doubt is about final keyword.,

i think a variable whether it is primitive or reference variable ., when it is declared as final variable we can't modify that value.,

but can we assign a final reference variable of an object to another reference variable of the same class?



It depends.

You can do something like this:



But you can't do this:



Once the reference variable is assinged an object, the reference cannot be changed. Note that the object state can change, such as below:

It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1079 times.
Similar Threads
Legal arguments in switch case statements
About synchronized code block.....
clarification on final methods
assigning a final value to a method local variable
class instance variables modifying
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:22:31.