0 day streak
java / beginner
Snippet

The Final Keyword

The 'final' keyword creates constants that cannot be reassigned once initialized.

snippet.java
java
1
2
final int MAX_SPEED = 120;
// MAX_SPEED = 130; // This would cause a compilation error
Breakdown
1
final int MAX_SPEED = 120;
Declares a constant integer that cannot be changed later.
2
// MAX_SPEED = 130;
Any attempt to modify a final variable results in an error.