What are immutable classes in Java?

Immutable classes are classes whose objects cannot be modified after they are created. Once an object is initialized, its state remains constant throughout its lifetime. Any change requires creating a new object rather than modifying the existing one.

Key Points

Example

When a String value is modified, Java creates a new String object instead of changing the original object.

final class Employee {

    private final String name;
    private final int id;

    public Employee(String name, int id) {
        this.name = name;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public int getId() {
        return id;
    }
}

public class Demo {

    public static void main(String[] args) {

        Employee emp = new Employee("Amol", 101);

        System.out.println(emp.getName());
        System.out.println(emp.getId());
    }
}

Characteristics of an Immutable Class

Benefits of Immutable Classes

Interview Tip

A concise interview answer is

An immutable class is a class whose objects cannot be modified after creation. Its fields are initialized once, typically through a constructor, and no setter methods are provided. Immutable classes are thread-safe, secure, and easier to maintain.

Last updated: 11 November 2026

Previous question: Why are immutable objects useful for concurrent programming?

Next question: How do you create an immutable class in Java?

More Core Java - Level II interview questions

All Core Java - Level II questions