Shailesh Vohra wrote:i did not understand your explanation Anbarasu Aladiyan.
Can one explain again...?
I just have to make my Objects also final....How to achieve it.?
What does meant by changing object's state?
It means changing the object's instance variable. So first make sure instance variables are not visible by putting private modifier.
And do NOT provide any setter methods. Because changing the instance a variable means changing the state of the object.
And in all the methods that changes the instance variable (for example subtract, add...) of the object.
First takes a copy of current object and make the changes in instance variables of new object. Then return that newly created object.
I think better you can refer string class documentation (source code).
Also be sure you know very well about immutable objects
Here is the concat() of string class: