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 a class immutable?

Answer Posted / rashmin

To make a class immutable follow the below steips

1. Make the class Final.
2. Make the instance variables private and final.
3. Make the methods in the class also final.

By doing the above 3 we can create a fully immutable class.

Is This Answer Correct ?    4 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we have try without catch block?

1030


Why string is immutable or final in java

1027


What carriage return means?

909


Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.

996


Why we use protected in java?

932


Can a static block throw exception?

1046


What are the two basic ways in which classes that can be run as threads may be defined?

1006


What is meant by class and object in java?

969


What is the primitive type byte?

941


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

1027


Is null or empty java?

928


Can we serialize arraylist in java?

958


What does split function do in java?

966


What is the use of arraylist class in java?

1008


is there a separate stack for each thread in java? : Java thread

929