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

Explain creating threads by implementing runnable class?

1103


what state does a thread enter when it terminates its processing? : Java thread

999


What is a final class in java?

974


Detail discussions on JVM, memory management and garbage collector.

931


Explain the difference between treeset and treemap in java?

932


Write code of any action class?

959


What two classes are used to read data only?

1044


Can you tell me range of byte?

950


When a thread is executing a synchronized method , then is it possible for the same thread to access other synchronized methods of an object ?

990


How list contains works in java?

934


What is Garbage Collection in Java

1038


What is the difference between length and length () in java?

891


What do you understand by the term singleton?

945


Can we override data members in java?

1092


A person says that he compiled a java class successfully without even having a main method in it? Is it possible?

1002