BY restricting the state change of a class object, I can make a class immutable?

Options
- No
- Yes


CORRECT ANSWER : Yes

Discussion Board
Immutable class

Immutable class can be made by following these rules:

1) Providing of "setter" methods is not recommended. Setter methods are the methods that modify fields or objects referred to by fields.
2) Making all fields final and private and it doesn't allow subclasses to override the methods.
3) Instance fields that includes references should not be allowed to have mutable objects.
4) Create copies of your internal mutable objects when necessary to avoid returning the originals in your methods.

Rohit Sharma 08-14-2014 05:47 PM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement