Immutable Class in Java Interview Questions | Immutable Class in Java

preview_player
Показать описание
This video explains concepts on Immutable Class in Java

What is immutable class?
Immutable means unmodified or unchangeable. Once the immutable class's objects are created, its object values and state cannot be changed.

Example - Primitive objects such as int, long, float, double, Wrapper classes(Integer, Float etc), String class, etc.

How to make a class Immutable?

1. Final class, which is declared as final so that it can't be extended.
2. All fields should be private and final so that direct access to the fields is blocked.
3. No Setters
4. If using a mutable object reference in immutable class, make a deep copy of it and then refer
Рекомендации по теме
Комментарии
Автор

Sir can you explain why the deep copy does not reflect the changed address value Need further few lines of explanation on this

abhisek-cbwn
Автор

explanation was very nice. could you please make video on exector framework

ranjeetsuman
join shbcf.ru