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

Why singleton pattern is better than creating singleton class with static instance?

1001


Can an interface extend a class?

996


If a method is declared as protected, where may the method be accessed?

1016


How would you use Bubble Sort to sort the number of elements?

1008


What is the difference between assignment and initialization?

1053


How does callback work in java?

1071


What is the difference between hashset and treeset in java?

1071


Explain creating threads by implementing runnable class?

1175


Can we use switch statement with strings?

1046


What is a variable declaration?

985


What is abstract class? Explain

1046


Can we modify the throws clause of the superclass method while overriding it in the subclass?

1037


Can a class be private or protected in java?

1065


What is the use of singleton?

967


What is primitive data type in java?

988