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

define the terminology association.

1108


What is boolean query?

995


why Java does not support multiple inheritances?

1176


What is the difference between call by reference and call by pointer?

978


Is java written in c?

968


What is a text string?

1096


Is age discrete or continuous?

1149


What is a numeric digit?

1095


What are the differences between getting and load method?

1206


How do you identify if jvm is 32-bit or 64-bit from java program?

974


Tell me about different OOPS concepts.

1013


What is a buffer in computer?

1013


What is the difference between actual and formal parameters?

958


If a variable is declared as private, where may the variable be accessed?

1069


What is the difference between multitasking and multithreading in Java

1196