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 have try without catch block?
Why string is immutable or final in java
What carriage return means?
Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.
Why we use protected in java?
Can a static block throw exception?
What are the two basic ways in which classes that can be run as threads may be defined?
What is meant by class and object in java?
What is the primitive type byte?
What is the difference in between cpp and java? Can u explain in detail?
Is null or empty java?
Can we serialize arraylist in java?
What does split function do in java?
What is the use of arraylist class in java?
is there a separate stack for each thread in java? : Java thread