+2 votes
in JAVA by (30.6k points)
How can we create an immutable class in Java?

1 Answer

0 votes
by (30.6k points)
We can create an immutable class by defining a final class having all of its members as final. Consider the following example.

public final class Employee{  

final String pancardNumber;  

  

public Employee(String pancardNumber){  

this.pancardNumber=pancardNumber;  

}  

  

public String getPancardNumber(){  

return pancardNumber;  

}  

  

}
Click here to read more about JAVA
Click here to read more about Insurance

Related questions

+2 votes
asked May 6, 2021 in JAVA by SakshiSharma (30.6k points)
0 votes
asked May 2, 2021 in JAVA by sharadyadav1986 (30.4k points)
...