How to make class immutable

Answer Posted / vijayakumar chinnasamy

Steps:
1. Create class as final class
2. Make all the properties i.e instance variable as final.
3. Avoid or make the least access for the setter method
for properties.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is consumer in java?

520


What are the 4 versions of java?

553


How can the checkbox class be used to create a radio button?

501


Write a program to find maximum and minimum number in array?

546


What are the main differences between the java platform and other platforms?

525






How does java pattern compile work?

539


What is null data type?

534


what is abstract class in Java?

650


What is java regex?

528


If you do not want your class to be inherited by any other class. What would you do?

559


What do you understand by the bean persistent property?

549


What is widening and narrowing in java? Discuss with an example.

554


What is the memory leak in java?

522


What is a concrete classes? Is Java object class is concrete class?

504


What is the function of java?

511