Explain how to make a class immutable In order to make a class immutable, the changing state of the class object must be restricted. This means restricting an assignment to a variable. This can be achieved by using ‘final’ access modifier. Make all methods in the class also ‘final’. Even a better approach is to make the class itself as ‘final’ class. So that it can not be subclass-ed, and no overriding occurs.
|