FINAL KEYWORD IN JAVA PROGRAMMING

in GEMS10 months ago

When you don't want any further modification to be done to your variable or a class or a method then final keyword comes to your aid. It can be applied to variable, class and method. Applying the final keyword to the variable makes sure that your value is initialized only once and no one can initialize it. Applying final to the method makes you sure that your method is not overridden and applying final keyword to the class makes sure that your class can't be inherited by others.


Screenshot_1.png

You can see the error in the console while compiling the code because I initialized the value of a again to 3.


Screenshot_2.png

Here again you can see the error when I tried to inherit the class that was declared with final keyord.