Design Patterns in Java

340 questions in the bank
Are you ready to take quiz?
Explore more
Logo
About the Quiz

Quiz will ask 20 randomly selected questions with allotted time of . You can take the quiz more than once. Once you submit the quiz, you can review how you have done, the correct the answers for each questions and the explanation for the correct the answer.

Quiz Topics

6 Modules

Creational Patterns

5 topics
1.

Abstract Factory Pattern

10 questions
2.

Builder Pattern

10 questions
3.

Factory Method Pattern

10 questions
4.

Prototype Pattern

10 questions
5.

Singleton Pattern

10 questions

Structural Patterns

7 topics

Behavioral Patterns

10 topics

General Principles

5 topics

Java-Specific Considerations

4 topics

Real-World Applications

3 topics
Sample questions

Which of the following statements about the Singleton Pattern in Java is true?

A Singleton class can have multiple instances.

The Singleton Pattern ensures that a class has only one instance.

The Singleton Pattern is used to create a new instance every time it is called.

The Singleton Pattern can be implemented using an enum.

What is the primary purpose of using the Singleton Pattern?

To restrict instantiation of a class to a single object.

To allow multiple instances of a class.

To provide a global point of access to the instance.

To improve performance by caching instances.

Which of the following is a common implementation technique for the Singleton Pattern in Java?

Lazy Initialization

Eager Initialization

Thread-safe Singleton using synchronized method

Static Block Initialization

What is a potential drawback of using the Singleton Pattern?

It can lead to resource wastage.

It introduces global state into an application.

It makes unit testing difficult.

It is not thread-safe by default.

In a thread-safe Singleton implementation using double-checked locking, which of the following statements is correct?

The instance is created inside a synchronized block.

The instance is checked twice before creation.

The volatile keyword is not needed.

It prevents multiple threads from creating multiple instances.

Quiz Topics

6 Modules

Creational Patterns

5 topics
1.

Abstract Factory Pattern

10 questions
2.

Builder Pattern

10 questions
3.

Factory Method Pattern

10 questions
4.

Prototype Pattern

10 questions
5.

Singleton Pattern

10 questions

Structural Patterns

7 topics

Behavioral Patterns

10 topics

General Principles

5 topics

Java-Specific Considerations

4 topics

Real-World Applications

3 topics