A Singleton class in Java ensures that only one instance of the class is created during the application’s lifecycle. It is a part of creational design patterns and is widely used in logging, database connections, caching, and configuration management.
Time limit: 0
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Which method is typically used to return the instance of a Singleton class?
Correct
Incorrect
Question 4 of 15
4. Question
How do you prevent creating multiple objects in a Singleton class?
Correct
Incorrect
Question 5 of 15
5. Question
What should the return type of getInstance() be?
Correct
Incorrect
Question 6 of 15
6. Question
Which keyword is used to store the only instance in a Singleton class?
Correct
Incorrect
Question 7 of 15
7. Question
What will happen if the constructor of a Singleton class is not private?
Correct
Incorrect
Question 8 of 15
8. Question
How can Singleton be broken in Java?
Correct
Incorrect
Question 9 of 15
9. Question
How do you prevent breaking Singleton using reflection?
Correct
Incorrect
Question 10 of 15
10. Question
Which Singleton type ensures lazy initialization?
Correct
Incorrect
Question 11 of 15
11. Question
What is eager initialization in Singleton?
Correct
Incorrect
Question 12 of 15
12. Question
Which Singleton implementation is thread-safe by default?
Correct
Incorrect
Question 13 of 15
13. Question
What is the disadvantage of eager initialization?
Correct
Incorrect
Question 14 of 15
14. Question
Which of the following ensures thread-safe Singleton implementation?
Correct
Incorrect
Question 15 of 15
15. Question
Can Singleton class implement interfaces or extend other classes?
Correct
Incorrect
Summary
The Singleton class in Java restricts instantiation to one object and is used in global configuration, logging, or database access. With approaches like eager initialization, lazy initialization, double-checked locking, and Enum Singleton, Java developers ensure thread-safety and optimal memory use.
At QuizOrbit, our team specializes in fun, informative quizzes across topics like general knowledge, technology, and entertainment. Boost your knowledge with our expert-designed quizzes.