What does final mean on a variable, a method and a class? Does a final reference make the object immutable?
Show the explanation
- final variable — can be assigned only once. A
static finalprimitive or String is a constant (static final int MAX = 100;). - final method — cannot be overridden by subclasses.
- final class — cannot be extended (
String,Integerand records are final).
A final reference cannot be pointed at another object, but the object can still change:
final List<String> names = new ArrayList<>();
names.add("Asha"); // allowed: the list object changes
// names = new ArrayList<>(); // compile error: reassigning the referenceFor a truly immutable object, make the class final, make all fields private final, provide no setters, and copy mutable inputs and outputs (or use List.copyOf). final fields also get a memory-model guarantee: once the constructor finishes, other threads see their correct values.
Original UniCircle question. Last reviewed 22 Oct 2026.
