crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

In Java how can we create immutable class?
Question Posted on 13 May 2021Home >> Java >> Java Questions >> In Java how can we create immutable class?

In Java how can we create immutable class?
Below are the some important facts about how to create immutable class
(1)First we declare class as final so that it cannot be extended.
(2)Second we create all fields as private so that direct access is not allowed.
(3)Third we will not provide setter methods for variables.
(4)Fourth create all mutable fields final so that its value can be assigned only once.
(5)Fifth we will initialize all fields via a constructor performing the deep copy.
(6)Sixth we will Perform cloning of objects in the getter methods to return a copy rather than returning the actual object reference.
0
0



.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions

What are the main difference between Array and Arraylist

What is classloader in Java and name of some classloader

Different modules of the Spring framework

Difference between Object and Class

Most important 15 aspects that Java Developer should learn in year 2020






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap