What is difference between constant in c plus plus and final in java?
The final keyword in Java has more in common with a C++ reference than it does with a C++ const. That is, a reference may only be assigned once, but the referenced object may still be modified. A C++ reference is the same as a constant pointer (rather than a pointer to const), insofar as the pointer cannot be modified, but the memory being pointed to can. This emulates some of the behaviour of the Java final keyword. But while a C++ const can easily be cast to a volatile, you simply cannot do that in Java. Moreover, a Java final class cannot be sub-classed, you simply cannot do that in C++. Comparing Java final to C++ const is somewhat pointless since they have absolutely nothing whatsoever in common; the list of differences could fill a book.