Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between const & final in java ?

 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear friends,


Both const & final are used to represent Constant value .

what is difference between const & final in java.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
const is not used to represent anything. It is reserved, but isn't used.
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
const is a reserved keyword that is not currently used. Its inclusion as a keyword was to assist compilers in catching out programs where this C++ keyword had been used in error.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final on a reference variable just means that the reference cannot be changed to reference a different object.

As far as I know, const in C++ means that you actually cannot change the object itself (for example by calling mutator methods).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic