Courseiva
Object-Oriented ProgramminghardMultiple ChoiceObjective-mapped

1Z0-811 Object-Oriented Programming Practice Question

Exhibit

public class Singleton { private static Singleton instance; private Singleton() {} public static Singleton getInstance() { if (instance == null) { instance = new Singleton(); } return instance; } }

Refer to the exhibit. What is the potential issue with this singleton implementation in a multithreaded environment?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Not thread-safe; two threads could simultaneously create different instances

The if-check and instantiation are not atomic. Two threads could both see instance == null and create separate instances, violating the singleton guarantee.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The getInstance() method should be non-static

    Why it's wrong here

    A static method is appropriate for a singleton to provide global access without an instance.

  • Compilation error because the constructor is private

    Why it's wrong here

    Private constructor is intended and does not cause a compile error.

  • Memory leak because instances are never garbage collected

    Why it's wrong here

    The singleton holds a reference, so it is not garbage collected, but this is not a leak; it's intentional.

  • Not thread-safe; two threads could simultaneously create different instances

    Why this is correct

    Correct. The check-then-act sequence is not synchronized.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.