Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What does final mean on a class, a method, a field and a local variable? Does a final field make the referenced object immutable?

final means "cannot be changed after this point", applied to different things: a final class cannot be subclassed, a final method cannot be overridden, a final field must be assigned exactly once, in its initializer or on every constructor path, and a final local variable or parameter cannot be reassigned. final applies to the reference, not the object, so a final List can still be modified. Final fields also get a special guarantee in the Java Memory Model: other threads see their constructed values once construction completes, without synchronization.

Why this question is asked

final is one of the most used keywords in Java, and one of the most misunderstood, because it means slightly different things in four places. The most common mistake in real code is believing that a final field makes an object immutable, which leads to shared lists being changed in surprising places. Interviewers ask this to check both the rules and that misunderstanding. In this answer, we will go through final on classes and methods, on fields, and on locals and parameters, see exactly what final does not protect, and finish with the memory model guarantee that makes final fields special for concurrency.

1Final on Classes and Methods

A final class cannot be extended. String, Integer and the other wrapper classes are final, which is part of why they are safe to share: nobody can create a subclass of String that behaves differently. A final method cannot be overridden by subclasses, though the class itself can still be extended.

Java
public final class Money { ... }
class Euro extends Money { } // compile error: cannot inherit from final Money
class Account {
public final void close() { ... } // subclasses may not change how closing works
}
class SavingsAccount extends Account {
@Override public void close() { } // compile error: close() cannot be overridden
}

We make a class final when we have not designed it for extension and want to keep the freedom to change its internals, and a method final when its behaviour is part of a contract subclasses must not break. Records and enums are implicitly final, or effectively so, for the same reason.

2Final on Fields

A final field must be assigned exactly once. Either it has an initializer, or every constructor must assign it on every path, and the compiler checks that. A final field without an initializer is called a blank final.

Java
class Order {
private final String id; // blank final
private final Instant created = Instant.now();
Order(String id) {
if (id == null) throw new IllegalArgumentException();
this.id = id; // assigned exactly once on every normal path
}
Order() { } // compile error: variable id might not have been initialized
void rename(String newId) {
this.id = newId; // compile error: cannot assign a value to final variable id
}
}

A static final field follows the same rule, but it must be assigned in its initializer or in a static block. A static final field of a primitive or String type with a constant initializer, such as static final int MAX = 50, is a constant variable, and the compiler copies its value into every place that uses it.

3Final on Local Variables and Parameters

A final local variable or parameter cannot be reassigned after it gets its value. Many teams write final on parameters to make reassignment impossible, while others find it noisy.

More important is the related idea of effectively final: a local variable that is never reassigned, even without the keyword. Lambdas, anonymous classes and local classes may only use local variables that are final or effectively final, because they capture a copy of the value.

Java
int limit = 10; // effectively final: never reassigned
Predicate<Integer> small = n -> n < limit; // OK
int count = 0;
list.forEach(x -> count++); // compile error: local variables referenced from a lambda must be final or effectively final

The reason for the rule is that the lambda keeps a copy of the value. If the variable could change later, the copy and the original would disagree, so Java forbids the situation instead of picking one.

4What final Does Not Protect

final freezes the reference stored in the variable, not the object the reference points to. A final field holding a List cannot be pointed at a different list, but the list itself is as mutable as ever.

Java
class Team {
private final List<String> members = new ArrayList<>();
List<String> members() { return members; }
}
Team t = new Team();
t.members().add("Asha"); // allowed: the list is mutable
System.out.println(t.members()); // [Asha]
// t.members = new ArrayList<>(); // this is what final forbids
What final freezes
Applied toEffectDoes not stop
classno subclasseschanging the object's fields
methodno overridingoverloading with other parameters
fieldassigned exactly oncechanges inside the referenced object
local or parameterno reassignmentchanges inside the referenced object
final always protects a name or a type, never the contents of an object.

To make the contents unchangeable, we need an unmodifiable object as well, such as List.of(...) or List.copyOf(input) taken in the constructor. A truly immutable class combines three things: final fields, values that are themselves immutable or defensively copied, and no methods that change state.

5The Memory Model Guarantee for Final Fields

Final fields have one more property that matters for concurrent code. The Java Memory Model promises that if an object is constructed without letting this escape, any thread that obtains a reference to it sees the final fields with the values the constructor gave them, even if the reference was passed through a data race without synchronization. Non-final fields have no such promise; another thread might see their default values.

This is what lets immutable objects such as String be shared freely between threads. The guarantee also covers objects reached through the final field, such as the elements of a final array filled in the constructor, as they were when the constructor ended.

6Follow-up questions

Does final make code faster?

Rarely in a measurable way. The JIT compiler already knows which methods are not overridden in the loaded classes and inlines them, so final methods are not much faster. The real benefits of final are design and correctness: fewer surprises, safe publication and clear intent.

Can reflection change a final field?

For ordinary instance fields, Field.setAccessible(true) followed by set() can still change a final field today, but the JVM may not make the change visible to code that already read or inlined the value. Static final fields, record fields and fields of hidden classes cannot be changed this way, and the JDK is moving towards restricting final field mutation further, so check your version.

Why are record fields final?

A record is meant to be a transparent carrier of its values, defined by its components. Making the fields final guarantees that a record's state is fixed after construction, which keeps equals and hashCode stable and makes records safe to share. Like any final field, though, a component that holds a mutable list is still mutable inside.

7Conclusion

In this answer, we saw that final means no subclasses on a class, no overriding on a method, exactly one assignment on a field, and no reassignment on a local or parameter, and that lambdas and inner classes can only capture final or effectively final locals. final freezes references, not objects, so a final List can still change unless we use an unmodifiable list. Final fields also carry a memory model guarantee: properly constructed objects show their final fields correctly to every thread, which is what makes immutable objects safe to share.

What to say in the interviewAbout 80 seconds aloud

Open with

final means the thing cannot change after a point, but what changes is different in each place. On a class it means no subclasses, like String; on a method it means subclasses cannot override it.

Then, if they want more

On a field it means it is assigned exactly once, either in its initializer or on every constructor path, and the compiler checks that; a static final with a constant initializer becomes a constant the compiler inlines.

On a local variable or parameter it means no reassignment, and related to that, lambdas and inner classes can only capture locals that are final or effectively final, because they capture a copy. The important limit is that final applies to the reference, not the object.

A final List field cannot point to a different list, but anyone holding it can still add to it, so for immutability I combine final fields with immutable values, such as List.copyOf in the constructor, and no mutating methods.

Final fields also have a Java Memory Model guarantee: if the object is constructed without this escaping, every thread that sees the reference sees the constructed values of its final fields, even without synchronization, which is what makes immutable objects safe to share between threads.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does final mean on a class, a method, a field and a local variable? Does a final...": https://scrivio-interview-library.netlify.app/java/classes-and-objects/2d14ac20a9/