How can we create our own immutable class
An immutable class in Java can be created by declaring the class as final, making all fields private and final, and not providing any setter methods.
Declare the class as final to prevent inheritance
Ma...read more
Immutable class in java means that once an object is created, we cannot change its content. In Java, all the wrapper classes (like Integer, Boolean, Byte, Short) and String class is immutable. We can create our own immutable class as well. Prior to going ahead do go through characteristics of immutability in order to have a good understanding while implementing the same. Following are the requirements:
The class must be declared as final so that child classes can’t be created.
Data members in the class must be declared private so that direct access is not allowed.
Data members in the class must be declared as final so that we can’t change the value of it after object creation.
Top Ernst & Young Java Developer interview questions & answers
Popular interview questions of Java Developer
Top HR questions asked in Ernst & Young Java Developer
Reviews
Interviews
Salaries
Users/Month