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 / al rahid

1. Declare the Class as final (this inherently makes all
member function final)
2. Declare member variables private (not necessarily final,
because private instance variable are accessed via public
member functions only, e.g. in java.lang.String class,
variable "hash" is declared as "private int hash;" with no
final keyword).

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a default constructor and also define copy contrucyor?

1161


What is a method type?

1036


How do you initialize an arraylist in java?

1095


What is the use of isempty in java?

1076


How do you detect memory leaks?

1111


What are java methods?

1191


How many bytes is 255 characters?

1034


What is the difference between checked exception and unchecked exception?

1058


What is unmodifiable list in java?

996


why Java does not support multiple inheritances?

1203


What is meant by collection in java?

1135


How many arguments can a method have java?

1067


Write a java program to count the number of words present in a string?

1021


what is the significance of listiterator in java?

1118


What is difference between protected and private?

1142