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

Differentiate between class and structure.

1063


Explain what do you mean by functional overloading in java?

953


What are the uses of synchronized keyword?

954


How to create com object in Java?

1013


FOR EXAMPLE WE R HAVING TWO LIST ELEMENTS ..BOTH LISTS CONTAINS ID,NAME,PLACE ..I NEED TO COMPARE BOTH IDS IN TWO LISTS,IF ID'S R SAME MEANS WE HAVE ADD THE DETAILS(LIKE NAME,PLACE) TO MAP...HOW IS POSSIBLE ?CAN ANY ONE SUGGEST?

3390


What is object-oriented paradigm?

1012


What is keyset in java?

1015


What does nullpointerexception mean?

1024


What is difference between stringbuffer and string?

900


What is initial size of arraylist in java?

995


Why do we need array in java?

960


How will you print number in reverse (descending) order in BST.

944


What is difference between printf and scanf?

1045


When should you use arraylist and when should you use linkedlist?

874


What is meant by collection in java?

1009