Declare a variable as final to prohibit its override or modification.
public class Main { public static void main(String[] args) { |
The final keyword, as a non-access modifier, applies to classes, attributes, and methods, rendering them immutable and uninheritable or unoverridable.
The final keyword is beneficial when you require a variable to consistently retain a specific value, such as PI (3.14159…).
The final keyword is categorized as a “modifier,” a concept you’ll delve deeper into in the Java Modifiers Chapter.