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

What is the difference between @before and @beforeclass annotation?

1016


what are three ways in which a thread can enter the waiting state? : Java thread

951


What is treemap in java?

899


Why set do not allow duplicates in java?

1006


What are the benefits of operations in java?

946


How is java hashmap implemented?

969


How will you compute size of a structure?

1076


What is api data?

947


How many types of keywords are there?

941


Can a method be static?

919


What is the properties class?

1033


What is the difference between array list and vector in java?

901


If you do not want your class to be inherited by any other class. What would you do?

947


What does the “static” keyword mean?

1048


What are default methods ?

988