0 votes
1 view
in Java by (2.4k points)
How does it work?

1 Answer

0 votes
by (5.4k points)

The final modifier is simply used so that the programmer isn't even able to change the value of a variable, once declared, unintentionally or intentionally. There are three cases in which the final modifier is used and they are as follows:

  • final Classes: When a class is declared as final, it is restricted from having subclasses.
  • final Variables: This is straightforward. If a value for a variable is assigned once (initialized), it cannot be changed. 
  • final Methods: Just as the final class cannot be inherited by a subclass or child class, a final method cannot be overridden. 

  

Final methods are generally used for security reasons as well as to provide bounds to the code so that some mishap(manual or automated) does not break the code or software upon deployment or update of the code. This is one of the most frequently asked java interview questions as well. You should most definitely clear up some of these concepts with certain hands-on. 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...