Feb 15, 2012

Immutable Class in Java

A class is immutable, only if when the instance of the class cant modify its content.. This can be achieved by

  • Making a class as Final
  • Make all the fields and methods as private.
Ex:
  • String Class 
    • When you create an instance of String class, say ex: new string(); then you cant modify the content  of String class with this object reference. 

No comments:

Post a Comment

Post a Comment

Note: Only a member of this blog may post a comment.