Header Ads

Importance of Final Modifier in Java

Hi 
Could you please tell me the Importance of Final Modifier in Java. I am a third year student and I need this for my semester examination.

Regard,
Jagan
Hi Jagan 
Thank you very much for writing to us!  Here goes your reply---

final Modifier in Java
final is a modifier in Java. The meaning changes context to context.The final modifier can be used before a class, method or variable. And its definition changes for each of them.

If final is used before a class, then that class cannot be sub-classed. we generally do not use final class but for security reason sometimes, we create the class as final.So no body can subclass it and can change the methods how they work. Like-String class
If final is used before a method, then that method cannot be overridden.In this case, nobody can redefined the method. like-println().
If final is used before a variable, then the value of that variable will act as a constant and thus, cannot be changed.

Please let us know if you need more info!!...Regards Devopriya

Powered by Blogger.