The final Keyword in Java


The final keyword is used in Java to restrict the user. It can be used with variables, methods, and classes.

Source Code

final int x = 10;
// x = 50; // will generate an error: cannot assign a value to a final variable

Use final to declare constants or prevent inheritance and overriding.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments