Difference Between Static and Final in Java


In this post, we will understand the difference between ‘static’ and ‘final’ keywords in Java.

Static

  • It can be applied to nested static class, variables, methods and block.

  • It is not required to initialize the static variable when it is declared.

  • This variable can be re-initialized.

  • It can access the static members of the class only.

  • It can be called only by other static methods.

  • Objects of static class can’t be created.

  • Static class can only contain static members.

  • It is used to initialize the static variables.

Final

  • It is a keyword.

  • It is used to apply restrictions on classes, methods and variables.

  • It can’t be inherited.

  • It can’t be overridden.

  • Final methods can’t be inherited by any class.

  • It is needed to initialize the final variable when it is being declared.

  • Its value, once declared, can’t be changed or re-initialized.

Updated on: 24-Mar-2021

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements