Skip to content
UniCircle
EasyConceptualInheritance

final variables, methods and classes

Question JAVA-INH-013

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 final primitive or String is a constant (static final int MAX = 100;).
  • final method — cannot be overridden by subclasses.
  • final class — cannot be extended (String, Integer and records are final).

A final reference cannot be pointed at another object, but the object can still change:

Java
final List<String> names = new ArrayList<>();
names.add("Asha");               // allowed: the list object changes
// names = new ArrayList<>();    // compile error: reassigning the reference

For 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.