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

Answers were Sorted based on User's Feedback



How to make class immutable..

Answer / a kumar

Make the class as final..
like
public final class String

Is This Answer Correct ?    7 Yes 2 No

How to make class immutable..

Answer / 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

How to make class immutable..

Answer / vijayakumar chinnasamy

Steps:
1. Create class as final class
2. Make all the properties i.e instance variable as final.
3. Avoid or make the least access for the setter method
for properties.

Is This Answer Correct ?    2 Yes 0 No

How to make class immutable..

Answer / ganesh reddy

declare calss as a final...

Is This Answer Correct ?    2 Yes 1 No

How to make class immutable..

Answer / 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

How to make class immutable..

Answer / atul

If declare class as final that means can not Inherited
in subclass.if declare final data members then must be
initializing at randomly or inside constructor otherwise
generate error

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is an array length?

0 Answers  


Is string is a data type?

0 Answers  


What is the maximum size of array in java?

0 Answers  


abstract class A{ int list []=new int [100]; A(int x,int y){ rondom n=new rondom(); for (int i==;i<100;i++); list [i]=x+r.next int(y-x+1); abstract sort (); abstract binary sarch(int temp); class B extends A{

3 Answers  


How many bytes are there?

0 Answers  


How many types of literals are there in JAVA?

0 Answers   Cap Gemini,


Can java list be null?

0 Answers  


How is string stored in java?

0 Answers  


Can a class be private in java?

0 Answers  


How will you measure that int takes up only 32 bits in memory?

2 Answers   Rolta,


What is thread life cycle in java?

0 Answers  


why the constructor should be used in class,if there is no constructor what will happen?

4 Answers  


Categories