[JAVA] final modifier

What is final

Use the final modifier to prevent the value once set in the variable from being changed later.

The final modifier is primarily used to set values such as constants that you do not plan to change.

For example, if you specify the final modifier for a variable as shown below, you cannot change the variable.

final class class name{
//processing
}

In addition to variables, the final modifier can be used for classes and methods when you don't want to change the contents. When specifying the final class, write the following.

final class class name{
//processing
}

Final is to make it impossible to change what you have decided

The final feature is that the programmer specifies (makes it impossible to change what you have decided). In final, the same keyword can be specified for variables and class methods, and each has a different meaning as shown below. It's the same keyword, but it's a little confusing because the meaning differs depending on the context. 1 final to variable Makes it impossible to reassign a value to a variable 2 Make it impossible to inherit the final class to the class 3 Make it impossible to override the final method to the method

Recommended Posts

final modifier
java final modifier
static modifier
JAVA learning history final modifier and static modifier
Access modifier [Java]
Meaning of final