Why immutable class declared as final in Java? Immutable class means, once object is created it can not be changed. Learn more about Immutable class in details : Create Immutable Class in Java | Advantages of immutable class in java Now lets see why we must declare immutable class as final in Java. If immutable class does not defined as final then any other class can extends that class and change properties of that class and broke the objective of immutability. So final class is important in immutability. Lets see using example. Programming.java public class Programming { private final String name; public Programming(String name) { this.name = name; } public String getName() { return name; } @Override public String toString() { ...
Welcome To Programming Tutorial. Here i share about Java Programming stuff. I share Java stuff with simple examples.