DSA Factory
Free Object-oriented basics lessonsObject-oriented basics · Stage 1 · Protecting state · Step 2

Immutability and value objects

What makes an object immutable, what final does and doesn't do, and why defensive copies matter. About 12 minutes.

Quick check

Which one is NOT needed to make a class immutable?

  1. ASynchronising every method
  2. BMaking the fields final
  3. CHaving no setters
Show the answer

Synchronising every method. Nothing changes, so there is nothing to synchronise.

Lock it in

4 questions on this idea

Short questions that apply the idea to new cases: trace it, work out a number, put steps in order. A wrong answer explains itself.

Answer them in your browserFree account, no card. Your progress is saved, and the idea comes back in a quick review later.
Sign up free to solve