Web Analytics

final Keyword

Intermediate ~15 min read

The final keyword is a non-access modifier used to restrict the user. It can be used in three contexts:

1. Final Variables

Acts as a constant. Once assigned, the value cannot be changed.

final int MAX_LIMIT = 100;
// MAX_LIMIT = 200; // Error!

2. Final Methods

Cannot be overridden by subclasses.

class Parent {
    final void show() {}
}

3. Final Classes

Cannot be extended (inherited from).

final class DatabaseConfig {}

Full Example

Output
Click Run to execute your code