
Asked in Capgemini and 13 others
How do you make a class immutable?

AnswerBot
2mo
An immutable class prevents modification of its instances after creation, ensuring data integrity.
Use 'final' keyword for fields to prevent reassignment.
Provide a constructor to initialize all fields....read more
Anonymous
1y
Declare the class as final so it can't be extended. Make all of the fields private so that direct access is not allowed. Don't provide setter methods for variables. Make all mutable fields final so th...read more
Sharukh Khan
3y
By Making class as a final and all data member as private.
Add answer anonymously...
Interview Questions from Popular Companies

3.7
• 8.8k Interviews

4.0
• 5.5k Interviews

3.5
• 4.2k Interviews

3.6
• 8k Interviews

3.7
• 6k Interviews

3.7
• 6.2k Interviews

3.5
• 4.2k Interviews

3.7
• 5.1k Interviews
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

