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
Can we override the static method?
What are the steps involved to create a bean?
How to convert string to byte array and vice versa?
What is the difference between error and an exception?
What is finalize() function in java?
What is the difference between class & structure?
What is indexof?
What is a Transient Object?
What is the difference between JDK and JVM?
what are the high-level thread states? : Java thread
Why arraylist is not synchronized in java example?
What is string pool?
How do you change an int to a string?
What is meant by inheritance and what are its advantages?
What are default methods ?