How can we design/implement singleton object?

Answers were Sorted based on User's Feedback



How can we design/implement singleton object?..

Answer / ravi

Make the constructor private

provide a static synchronized method to get the Instance.

this should make the object singleton for that jvm instance

Is This Answer Correct ?    3 Yes 0 No

How can we design/implement singleton object?..

Answer / todd d. roling

public enum Singleton {
INSTANCE;
}

Is This Answer Correct ?    2 Yes 1 No

How can we design/implement singleton object?..

Answer / jayashri

by declaring the constructor as private and we have to create public static method which returns the address of single object.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Design Patterns Interview Questions

Is dependency injection a design pattern?

0 Answers  


Give me example of chain of responsibility design pattern?

0 Answers  


What is the publish/subscribe model?

1 Answers  


What are sequence diagrams, collaboration diagrams and difference between them ?

8 Answers   ACET, CT, CTS, Infosys,


Can we have this pattern implemented using static class?

0 Answers  






What is design pattern ?

4 Answers   Accenture,


Why do we need singleton pattern?

0 Answers  


What is the behavioral design pattern?

0 Answers  


What is software 'quality'?

2 Answers  


write 5 best test cases like any password?password should be mixed case with atlest one number or special characters?

2 Answers   Wipro,


Why have we used synchronized here?

0 Answers  


When to Use a Factory Pattern?

3 Answers  


Categories