- A
Declare the balance field as volatile.
Why wrong: volatile ensures visibility but not atomicity of compound operations.
- B
Use AtomicLong and convert to double.
Why wrong: AtomicLong is for long, not double. AtomicDouble does not exist in standard Java.
- C
Wrap the balance field in a synchronized block within each method using a separate lock object.
Why wrong: This is essentially the same as synchronizing the methods but adds boilerplate; not the most straightforward.
- D
Synchronize the deposit and withdraw methods.
Synchronizing ensures both visibility and atomicity for these methods.
Quick Answer
The correct answer is to synchronize the deposit and withdraw methods. This resolves the race condition on the balance field because the compound operations `balance += amount` and `balance -= amount` are not atomic; each involves a read-modify-write sequence that, when executed by multiple threads under heavy load, leads to lost updates and incorrect balance calculations. Synchronizing these methods ensures mutual exclusion, so only one thread can modify the balance at a time, preserving data integrity without requiring external locks. On the Oracle Java Foundations 1Z0-811 exam, this question tests your understanding of thread safety and the `synchronized` keyword as a fundamental concurrency mechanism. A common trap is assuming `getBalance()` also needs synchronization—while it should be synchronized for visibility, the core fix here targets the write methods. Memory tip: think “sync the write, not just the read” to remember that compound assignments are the root cause of race conditions.
1Z0-811 Java Basics and Syntax Practice Question
This 1Z0-811 practice question tests your understanding of java basics and syntax. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
A financial trading application processes high-volume transactions. The system uses a multithreaded architecture where multiple threads update a shared Account object's balance field. Recently, intermittently incorrect balance calculations have been reported. Developers suspect a race condition on the balance field. The Account class is defined as follows:
public class Account {
private double balance = 0.0;
public void deposit(double amount) { balance += amount; }
public void withdraw(double amount) { balance -= amount; }
public double getBalance() { return balance; }
}Threads are created using ExecutorService with a fixed thread pool. The issue occurs only under heavy load. Which course of action should the development team take to resolve the issue while maintaining performance?
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
Synchronize the deposit and withdraw methods.
Option D is correct because synchronizing the `deposit` and `withdraw` methods ensures mutual exclusion on the `balance` field. In Java, the compound operations `balance += amount` and `balance -= amount` are not atomic; they involve a read, modify, and write sequence. Synchronization guarantees that only one thread executes these methods at a time, preventing race conditions and ensuring correct balance calculations under heavy load.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Declare the balance field as volatile.
Why it's wrong here
volatile ensures visibility but not atomicity of compound operations.
- ✗
Use AtomicLong and convert to double.
Why it's wrong here
AtomicLong is for long, not double. AtomicDouble does not exist in standard Java.
- ✗
Wrap the balance field in a synchronized block within each method using a separate lock object.
Why it's wrong here
This is essentially the same as synchronizing the methods but adds boilerplate; not the most straightforward.
- ✓
Synchronize the deposit and withdraw methods.
Why this is correct
Synchronizing ensures both visibility and atomicity for these methods.
Related concept
Read the scenario before looking for a memorised answer.
Common exam traps
Common exam trap: answer the scenario, not the keyword
Oracle often tests the misconception that `volatile` solves all concurrency issues, but the trap here is that `volatile` does not provide atomicity for compound operations, so candidates who choose Option A fail to recognize that `balance += amount` is not a single atomic step.
Detailed technical explanation
How to think about this question
Under the hood, the `synchronized` keyword in Java uses intrinsic locks (monitors) associated with the object instance. When a thread enters a synchronized method, it acquires the lock, and other threads are blocked until the lock is released. This ensures that the read-modify-write operations on `balance` are executed atomically. In high-volume trading systems, using `synchronized` methods can become a bottleneck; a more performant alternative would be to use `ReentrantLock` with finer-grained locking or `AtomicReference<Double>` with compare-and-swap, but for the 1Z0-811 exam, method-level synchronization is the correct and simplest solution.
KKey Concepts to Remember
- Read the scenario before looking for a memorised answer.
- Find the constraint that changes the correct option.
- Eliminate answers that are true in general but not in this case.
TExam Day Tips
- Watch for words such as best, first, most likely and least administrative effort.
- Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A practitioner preparing for the 1Z0-811 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
- →
Java Basics and Syntax — study guide chapter
Learn the concepts, then practise the questions
- →
Java Basics and Syntax practice questions
Targeted practice on this topic area only
- →
All 1Z0-811 questions
509 questions across all exam domains
- →
Oracle Java Foundations 1Z0-811 study guide
Full concept coverage aligned to exam objectives
- →
1Z0-811 practice test guide
How to use practice tests most effectively before exam day
Related practice questions
Related 1Z0-811 practice-question pages
Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.
What is Java practice questions
Practise 1Z0-811 questions linked to What is Java.
Java Basics and Syntax practice questions
Practise 1Z0-811 questions linked to Java Basics and Syntax.
Primitives, Strings and Operators practice questions
Practise 1Z0-811 questions linked to Primitives, Strings and Operators.
Control Flow and Loops practice questions
Practise 1Z0-811 questions linked to Control Flow and Loops.
Arrays and Methods practice questions
Practise 1Z0-811 questions linked to Arrays and Methods.
Object-Oriented Programming practice questions
Practise 1Z0-811 questions linked to Object-Oriented Programming.
Exception Handling and Development Tools practice questions
Practise 1Z0-811 questions linked to Exception Handling and Development Tools.
1Z0-811 fundamentals practice questions
Practise 1Z0-811 questions linked to 1Z0-811 fundamentals.
1Z0-811 scenario practice questions
Practise 1Z0-811 questions linked to 1Z0-811 scenario.
1Z0-811 troubleshooting practice questions
Practise 1Z0-811 questions linked to 1Z0-811 troubleshooting.
Practice this exam
Start a free 1Z0-811 practice session
Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.
FAQ
Questions learners often ask
What does this 1Z0-811 question test?
Java Basics and Syntax — This question tests Java Basics and Syntax — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: Synchronize the deposit and withdraw methods. — Option D is correct because synchronizing the `deposit` and `withdraw` methods ensures mutual exclusion on the `balance` field. In Java, the compound operations `balance += amount` and `balance -= amount` are not atomic; they involve a read, modify, and write sequence. Synchronization guarantees that only one thread executes these methods at a time, preventing race conditions and ensuring correct balance calculations under heavy load.
What should I do if I get this 1Z0-811 question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.