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’s the difference between unit, integration and functional testing?

606


What is the purpose of lambda expressions?

576


What is java english?

483


When should I use a singleton?

545


what is session in java?

735






What is method with example?

570


Explain the term virtual machine?

580


What does index mean in java?

529


What is the difference between jdk, jre, and jvm?

562


Explain about method local inner classes or local inner classes in java?

561


what is instanceof operator used in java?

583


Why java is called not pure object oriented language?

568


Explain heap sort?

692


How is it possible in java programming for two string objects with identical values not to be equal under the == operator?

556


When do we need to use internal iteration? When do we need to use external iteration?

599