Java - Class final Keyword

What is final keyword

The declaration marked with final does not allow modifying or replacing its original value or definition.

Contexts

The final keyword can be used in the following three contexts:

  • A variable declaration
  • A class declaration
  • A method declaration

final variable declaration

A final variable can be assigned a value only once.

The value of a final variable cannot be modified once it has been set.

final class

A final class cannot be extended (or subclassed).

final method

A final method cannot be redefined (overridden or hidden) in the subclasses.

Related Topics

Quiz