Junior — Middle
Milline on Final modifikaatori Java keeles ja millal seda kasutatakse?
sobes.tech AI
Vastus AI-lt
The final modifier in Java is used to restrict changes:
- For variables: the value can be assigned only once, after which it becomes a constant.
- For methods: the method cannot be overridden in subclasses.
- For classes: the class cannot be inherited.
Example of using final for a variable:
final int MAX_USERS = 100;
final is used to enhance code security, prevent accidental changes, and ensure immutability.