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

What is the flag in java?

1113


Is linked list a linear or non-linear data structure?

1013


Is it possible to write a regular expression to check if string is a number?

1074


What is e in java?

1012


what is mutual exclusion? : Java thread

1070


What is the use of generics? When was it added to the Java development Kit?

1066


What is the difference between preemptive scheduling and time slicing in java programming?

1074


What is the difference between public, private, protected, and friend access?

1104


Can substring create new object?

1189


How do you convert an int to a double in java?

1113


What is the formula to calculate percentage?

1072


What is meant by method overriding?

1172


What is the difference between scrollbar and scrollpane?

1132


How is string stored in java?

1119


What do you understand by weak reference?

1067