top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Can somebody explain immutable classes in JAVA

+4 votes
114 views
Can somebody explain immutable classes in JAVA
posted Jan 18, 2014 by Neeraj Pandey

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

Immutable objects are simply objects whose state (the object's data) cannot change after construction. Examples of immutable objects from the JDK include String and Integer.

Guidelines to make a class immutable:
1) Don’t provide “setter” methods — methods that modify fields or objects referred to by fields.
2) Make all fields final and private
3) Don’t allow subclasses to override methods
4) Special attention when having mutable instance variables

answer Jan 19, 2014 by Atul Mishra
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...