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 / khizar khan

1) Make a class fianl like final class A{}

2) Then use the property as private and final
ex:
final class A{
private final int salary;

}
3)Now make a Constructor to initilize the values
ex:
A(int a)
{ this .salary=a;
}
4)Now use the gtter mathod to acces the values
ex:
final class A{
private final int salary ;
A( int a)
{
this.salary=a;

}
public int getSalary()
{
return salary;

}

}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we clone singleton object in java?

1015


What is scope & storage allocation of global and extern variables? Explain with an example

1038


What is volatile keyword in java

1118


What is collection api?

1042


what r advatages of websphere? & how to deploy?

2185


What is java in layman terms?

1007


What is a boolean structure?

1083


When is finally block not called?

1089


How do you calculate square roots?

1157


can I implement my own start() method? : Java thread

991


Difference between arraylist and hashset in java?

1126


Can you give few examples of final classes defined in java api?

1004


What do you understand by the term singleton?

994


What is the original name of java?

1098


What is a constructor overloading in java?

1034