Can class be immutable? (java)
Yes, a class can be immutable. You can make a class as final to make it immutable
Immutable classes : are also known as final classes. A class which you can't inherit (can't change the definition by extending it) is called as
immutable class. In some languages it is also called as shield classes. Eg: String class in java is immutable class, you can't inherit it.
use case: If you don't want any one to inherit your class and change the basic functionality of your class, then make it as immutable class.
This can be achieved by making your class as final class by using "final" keyword before your class.
Back To Top