What is the use of final keyword in JAVA
March 21, 2015
Final keyword is used to make member’s value unchanged. Simple definition of final keyword is to make variable’s values non-changeable. Once you declare any member as final you cannot modify it. To make any member as final we simply need to put final keyword before data type.
final int a = 10;
Variable/member marked as final should be initialized at the time of declaration. The reason is that value of final variable is fixed, so we need to provide value at the time of declaration.
Yes, we can modify final members inside Constructor. Because Constructor called when class is created and it will also initialize final variables.