• Post Reply Bookmark Topic Watch Topic
  • New Topic

Final Reference Variable  RSS feed

 
Jeena Jeen
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple question about Final reference variables.
I read in the book that final modifier assures that a reference variable cannot be referred to different Object but state of the object can be changed.
Does it only mean that f1 can not refer to f2( or any other object). Or it means more than that?

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct, when you make a 'reference' as a constant(final), your 'reference' refer to the same 'heap space' where your object is get created, that's mean, reference "f1" can't point other than that memory space(object allocated space), but that's dosen't mean you can not change the instance variable which resides in that object.

HTH
 
Jeena Jeen
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sagar
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Pleasure
 
NagarajGoud uppala
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jeen,
yes it means not only f2 any other object
but it can allow to change the state
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great and solid answer
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!