Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (6.5k points)
How does it work?

1 Answer

0 votes
by (11.3k 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. 

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 12, 2021 in Java by Jake (7k points)
0 votes
0 answers
asked Jun 24, 2021 in Java by Jake (7k points)

Browse Categories

...