Using final Keyword in Java


The final keyword is used to define an entity that can only be assigned once.

Source Code

final int x = 100;
public void myMethod() {
    // x = 50; // This would generate an error: cannot assign a value to final variable x
    System.out.println(x);
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments