How to make a class immutable?

Answer Posted / kanchan

To make a class immutable,
1. Don't provide any methods that modify the object.
2. Ensure that no methods may be overridden. Mark the class
as final. Make all fields final and private.

Is This Answer Correct ?    63 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we declare a class static?

517


What is an interface in java?

538


What is natural ordering in java?

504


How much ram can a 64 bit processor theoretically?

440


What is return null in java?

489






What is data member in java?

483


What is tree in java?

466


What is a nullable field?

549


What if static is removed from main method?

547


A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.

524


How java uses the string and stringbuffer classes?

489


What is Java Package and which package is imported by default?

564


How to store image in arraylist in java?

489


what is meant by Byte code concept in Java?

579


What do you mean by scope of variable?

462