How do you make a class immutable in java?



How do you make a class immutable in java?..

Answer / Ravi Ranjan

To make a class immutable in Java, make its fields final (to ensure they cannot be modified), ensure the constructor is private, and provide factory methods for creating instances.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More J2EE Interview Questions

Which one should we prefer while using bean ? managed bean annotation or faces-config

1 Answers  


Is java safe to download?

1 Answers  


What is distributed application?

1 Answers  


What is component-managed sign-on ?

1 Answers  


What is application client module?

1 Answers  


why we are using XML?

14 Answers   TCS,


What is ejb container provider?

1 Answers  


whay java does not support bass by reference

1 Answers   NIIT,


What is wildfly java?

1 Answers  


What is considered as a web component?

1 Answers  


What is j2ee product provider?

1 Answers  


What is java 2 platform, micro edition (j2me)?

1 Answers  


Categories