How to make a class immutable?

Answer Posted / venkata siva reddy

1.Make the class as final.
2.Make all the properties (variables) as private and final
3.Provide only getter methods for variables.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What class of exceptions are generated by the java run-time system?

640


What is pre increment and post increment in java?

514


What are the main differences between notify and notifyAll in Java?

595


List types of storage classes in java?

632


how to handle exceptions in ejb?

1882






What does file separator do in java?

547


What happens if an exception is throws from an object's constructor?

639


Is string a class in java?

521


What is default exception handling in java?

581


What is meant by nested loop?

546


What do you mean by aggregation?

580


Can we use string in switch case in java?

578


How do you sort in ascending order in java?

532


What is an infinite loop?

555


does java support pointers?

574