Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to make class immutable

Answer Posted / kanchan

1. Don't provide any methods that modify the object
2. Ensure that no methods may be overridden. This prevents
careless or malicious subclasses from compromising the
immutable behavior of the class. Preventing
method overrides is generally done by making the class final
3. Make all fields final.
4. Make all fields private. This prevents clients from
modifying fields directly.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is better stringbuilder or stringbuffer?

870


What is the difference in between cpp and java? Can u explain in detail?

1029


What is meant by anonymous class?

979


Can a variable be local and static at the same time?

945


Can size_t be negative?

1073


What is a final class ?

1083


How can you traverse a linked list in java?

1073


What is data type example?

903


What are disadvantages of java?

960


Is java still necessary?

1005


Can a static method be overridden in java?

968


Explain the concept of proper inheritance?

1014


What is get () in java?

975


Explain about join() method?

903


What is the difference between serializable and externalizable interfaces?

1027