What is singleton class?

Answers were Sorted based on User's Feedback



What is singleton class?..

Answer / muthu

hi,
this is muthu,

i have created singleton class A this class file warped
(warfile) and same singleton class A that class also warped
(warfile)so both war file deployed inthe Application server
then start the server.so how many instance create in JVM?
SO PLE KINDLY REPLAY TO ME...

THKS
MUTHU

Is This Answer Correct ?    0 Yes 0 No

What is singleton class?..

Answer / ashish srivastava

public class Singleton {

private static Singleton s = new Singleton();

private Singleton(){

}

public static Singleton getObject(){
return s;
}

}

Is This Answer Correct ?    0 Yes 0 No

What is singleton class?..

Answer / nagarjuna

Singletonclass is a class which can be instantiated only once.
public class Singleton
{
private static single = new Singleton();

Private Singleton();
{}
}

For a singleton class, the constructor is made private and
a static variable is used for instatiating the class.

Is This Answer Correct ?    4 Yes 6 No

What is singleton class?..

Answer / ajay

how constructor can be private???????

Is This Answer Correct ?    0 Yes 2 No

What is singleton class?..

Answer / 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

What is singleton class?..

Answer / ravikiran(aptech mumbai)

singleton class is the class contains only one object

Is This Answer Correct ?    39 Yes 71 No

Post New Answer

More Core Java Interview Questions

How does arrays sort work in java?

0 Answers  


Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?

0 Answers  


How much is a java license?

0 Answers  


What are the features of java?

0 Answers  


is there any function in java to make the text to blink?

6 Answers  






Difference between Web-based applications,Client- Server applications and Distributed applications?

3 Answers   Infosys,


Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.

0 Answers   Fidelity,


What is a get method?

0 Answers  


What is a variable simple definition?

0 Answers  


How is a variable stored in memory?

0 Answers  


What is variable in java?

0 Answers  


What is a treeset in java?

0 Answers  


Categories