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...

can any one send me the example program of immutable class?

Answer Posted / jinxuan

public class SingletonTest
{
public static void main(String[] args)
{
Singleton singleton = Singleton.getInstance();
Singleton singleton1 = Singleton.getInstance();

System.out.println(singleton == singleton1);
}
}

class Singleton
{
private static Singleton singleton = new Singleton();
private Singleton()
{

}

public static Singleton getInstance()
{
return singleton;
}

}
it means whenerver you new a Object,it returns the same
object address, i'ts Singleton Pattern. so your object is
immutable class

Is This Answer Correct ?    0 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of garbage collection in java?

1043


Name the components that are termed to be Heavy-weight component but available in Light-weight components?

2441


What is the difference between a vector & an array list?

1104


How do you check whether the list is empty or not in java?

921


Why synchronization is important in java?

985


What is a dot notation?

957


Explain garbage collection in java?

919


Difference between overriding and overloading in java?

1007


Which of the following is not an isolation level in the JDBC

2074


Explain the difference between a Thread and a Process.

940


Why hashset is used in java?

1000


What is the size of a string in java?

934


What is exception in java?

1013


What is replacefirst in java?

1024


What is namespace in java?

940