What is final keyword in Java?

final is a special keyword in Java that is used as a non-access modifier. A final variable can be used in different contexts such as:

  • final variable: When the final keyword is used with a variable then its value can't be changed once assigned. In case the no value has been assigned to the final variable then using only the class constructor a value can be assigned to it.
  • final method
: When a method is declared final then it can't be overridden by the inheriting class.
  • final class
: When a class is declared as final in Java, it can't be extended by any subclass class but it can extend other class.