Explain how to make a class immutable - Java

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.
Java methods are virtual by default. Comment
Java methods are virtual by default. The virtual methods are the methods of subclasses...
How a class implements an interface in Java.
First ,the interface is to be defined. Defining an interface is placing the method signatures...
Concrete class vs. Abstract class vs. Interface in Java
A concrete class has concrete methods, i.e., with code and other functionality...
Post your comment