Get Started
1054

Q: What is immutable object? Can you write immutable object ?

  • Show Answer
  • Workspace

Answer :
Explanation :

Immutable classes are Java classes whose objects can not be modified once created. Any modification in Immutable object result in new object. For example is String is immutable in Java. Mostly Immutable are also final in Java, in order to prevent sub class from overriding methods in Java which can compromise Immutability. You can achieve same functionality by making member as non final but private and not modifying them except in constructor.

The Most Comprehensive Exam Preparation Platform

Get the Examsbook Prep App Today