Home » Interview » Technology

What is immutable object? Can you write immutable object ?

Correct Answer: 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

← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion