public class Test {
private final String url;
public Test(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
}
The Test class has:
- Only one instance variable which is private and final.
- No setters.
- The only way to initialize the instance variable is through the constructor.
- And once the URL is set, it can't be modified even in getUrl even if that method is overridden by any subclass of Test.
But a book that I am reading says the above Test class is mutable because:
Neither class is final so that it can be extended, and a subclass can override instance methods. But the Test class does not really have any instance methods other than the constructor.
Nor is the constructor private.
Can you please help me in understanding why the Test class is mutable?