What is the use of final keyword in JAVA

Fetching Comments ...

Final keyword in java

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.

Example of final keyword:

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.

Can we modify final members after declaration?

Yes, we can modify final members inside Constructor. Because Constructor called when class is created and it will also initialize final variables.

Share This:

LearnPainLess On Instagram

Get The Best Of All Hands Delivered To Your Inbox

Subscribe to our newsletter and stay updated.