0 day streak
java / beginner
Snippet

Declaring Constants with final

In Java, the 'final' keyword is used to create constants. Once a value is assigned to a final variable, it cannot be changed throughout the program execution.

snippet.java
java
1
2
final int LIMIT = 50;
// LIMIT = 100; // This line would cause a compile-time error
Breakdown
1
final int LIMIT = 50;
The 'final' keyword ensures the variable LIMIT remains 50 and cannot be reassigned.