How to make a class immutable?

Answer Posted / rashmin

To make a class immutable follow the below steips

1. Make the class Final.
2. Make the instance variables private and final.
3. Make the methods in the class also final.

By doing the above 3 we can create a fully immutable class.

Is This Answer Correct ?    4 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the fileinputstream and fileoutputstream?

560


Can static methods be inherited?

521


How will you reverse a link list without using recursion?

579


Give me some null interfaces in java?

590


How do you identify independent and dependent variables?

493






How to write custom exception in java?

590


What is overloading and overriding in java?

646


How to sort an array from smallest to largest java?

528


What is the loop in java?

559


What is the use of pattern in java?

496


Name container classes in java programming?

579


How do you declare an empty string?

605


What is a module function?

547


What is finalize() function in java?

543


In case of inheritance what is the execution order of constructor and destructor?

626