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 are the types of relation?

1001


What is oop in java?

971


How do you reverse a string in java?

1065


What about static nested classes in java?

1083


Can a class have an interface?

930


What do u mean by variable?

997


What is output buffer?

990


What are different types of arrays?

963


What is the difference between Java1.4 and Java1.5

2264


Why are arrays useful in java?

984


What is difference between adapter class and listener?

977


How can we create objects if we make the constructor private ?

957


What is the difference between a constructor and a method?

1173


What is the difference between a window and a frame in java programming?

1092


What is the maximum size of list in java?

917