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

What is singleton class?

Answer Posted / marshallsudhan

singleton class - has single Instance.

The Singleton is a useful Design Pattern for allowing only
one instance of your class, but common mistakes can
inadvertently allow more than one instance to be created.

The Singleton's purpose is to control object creation,
limiting the number to one but allowing the flexibility to
create more objects if the situation changes. Since there
is only one Singleton instance, any instance fields of a
Singleton will occur only once per class, just like static
fields.

//Eg Pgm.

class Sample
{
void m1()
{
System.out.println("Method m1");
}
void m2()
{
System.out.println("Method m2");
}
private Sample()
{
System.out.println("Constructor");
}
public static void main(String[] args)
{
Sample s = new Sample();
s.m1();
s.m2();
}

Is This Answer Correct ?    49 Yes 74 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by constant time complexity?

1136


What is the driver class?

966


List primitive java types?

978


How are this() and super() used with constructors in java programming?

1015


What means public static?

995


Is it possible to use Semaphore/ Mutex in an Interrupt Handler?

1032


Explain with example the concept of constant variable in java.

1098


What is the static block?

1004


How do you add an arraylist to an array in java?

930


What are the methods to rectify ambiguities in the interfaces in JAVA?

1028


How many types of equations are there?

958


Is zero a positive integer?

988


Explain importance of finally block in java?

980


What is subsequence of a string?

1035


Can we split string with in java?

948