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 module with example?

1005


What do bitwise operators do?

1010


Does java allow overriding static methods ?

1112


Difference between method overloading and method overriding in java ?

1081


extending thread class or implementing runnable interface. Which is better? : Java thread

997


What is a protected class in java?

995


What is passing value java?

1056


Why local variables are stored in stack?

974


Should a main method be compulsorily declared in all java classes?

1064


What if constructor is protected in java?

1116


What is extension method in java?

1039


How to obtain a performance profile of java program

1030


What is the different types of functions?

1057


What is meant by JVM? Is JVM platform independent or not?

1077


Why is a constant variable important?

954