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 / venu gopala reddy

a better approach. Make the immutable class itself final. Hence cannot make any sub classes, so no question of over ridding.
write code for user immutable class:-


final class ImmutableVenu{

private final int count;

private String phno="9742108000";

public ImmutableVenu(int paramCount,String paramPhno){

count=paramCount;

phno=paramPhno;
}

public int getCount(){
return count;
}

public String getString(){
return paramPhno;
}
}

public static void main(String ar[])
{

ImmutableVenu immu=new ImmutabeVenu();
s.o.p(immu.getCount());
s.o.p(immu.getPhno());
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain different ways of creating a thread?

1051


Give differences between Quicksort & Mergesort. When should these sorts be used and what is their running time?

1066


Why does java have two ways to create child threads?

949


What is collection api?

1044


Explain the protected field modifier?

1079


Write a program to print all permutations of string?

1113


What do you mean by an object in java?

1126


What is the ==?

880


What is treeset and treemap in java?

1065


Difference between method overloading and overriding.

1079


How a variable is stored in memory?

986


What is the size of integer?

1092


What is assembly condition codes?

988


What is Gang of four design patterns

1051


how come we know the object is no more used in the class?

6464