Question 287 of 509
Primitives, Strings and OperatorshardMultiple ChoiceObjective-mapped

Quick Answer

The answer is to add parentheses: `if ((x & y) == 1)`. This is necessary because in Java, the bitwise AND operator `&` has lower precedence than the equality operator `==`, so the original code `x & y == 1` is parsed as `x & (y == 1)`, which first evaluates the boolean `y == 1` (resulting in `true` or `false`, implicitly converted to `1` or `0`) and then performs a bitwise AND with `x`—not the intended check that both numbers share the same least significant bit set. On the Oracle Java Foundations 1Z0-811 exam, this question tests your understanding of operator precedence in bitwise operations, a common trap where developers assume `&` binds tighter than `==`. The fix ensures the bitwise AND happens first, producing an integer result that is then compared to `1`. Memory tip: think "bitwise before equals" is false—always parenthesize your bitwise comparisons.

1Z0-811 Primitives, Strings and Operators Practice Question

This 1Z0-811 practice question tests your understanding of primitives, strings and operators. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. 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 developer is writing a bitmask validation method. The method should return true if both input integers (x and y) have exactly the same least significant bit set. The developer writes: if (x & y == 1) { return true; } However, the condition never evaluates to true even when both numbers are odd (least significant bit = 1). Debugging shows that x and y are positive integers. What is the root cause and the correct fix?

Clue words in this question

Noticing these words before you look at the options changes how you read each choice.

  • Clue: "least"

    Why it matters: You want the option with minimum overhead, fewest steps, or lowest impact — not the most feature-rich or comprehensive answer.

  • Clue: "never"

    Why it matters: Absolute qualifier. True only if the statement has zero exceptions — be cautious of options that seem obvious but break down in edge cases.

Question 1hardmultiple choice
Full question →

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

Add parentheses: if ((x & y) == 1) { ... }

In Java, the bitwise AND operator & has lower precedence than the equality operator ==. Therefore, x & y == 1 is parsed as x & (y == 1), which performs a boolean comparison (y == 1) and then bitwise ANDs x with the boolean result (true = 1, false = 0), not what was intended. The fix is to add parentheses: (x & y) == 1. Option A corrects the precedence. Option B uses logical AND (&&) which is not bitwise. Option C uses bitwise OR (|) which is not correct for checking both bits set. Option D uses modulo (%), which works for odd check but not for bitmasking in general.

Key principle: Count usable hosts — not total addresses — and remember that the network and broadcast addresses are not available to hosts in standard IPv4 subnets.

Answer analysis

Option-by-option breakdown

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

  • Use modulo: if (x % 2 == 1 && y % 2 == 1) { ... }

    Why it's wrong here

    Modulo works to check if both are odd, but the requirement is about bitmasking using the & operator; this changes the approach entirely.

  • Add parentheses: if ((x & y) == 1) { ... }

    Why this is correct

    Parentheses ensure the bitwise AND is performed before the comparison, correctly checking if the least significant bit of x & y is 1.

    Clue confirmation

    The clue words "least", "never" in the question point toward this answer.

    Related concept

    CIDR notation defines the prefix length.

  • Use bitwise OR: if (x | y == 1) { ... }

    Why it's wrong here

    Bitwise OR does not check that both bits are set; it checks if at least one is set. Also, the same precedence issue applies.

  • Use logical AND: if (x && y == 1) { ... }

    Why it's wrong here

    && is a logical operator and requires boolean operands; x is an integer, so this will not compile.

Common exam traps

Common exam trap: usable hosts are not the same as total addresses

Subnetting questions often tempt you into counting all addresses. In normal IPv4 subnets, the network and broadcast addresses are not usable host addresses.

Detailed technical explanation

How to think about this question

Subnetting questions test whether you can identify the network, broadcast address, usable range, mask and correct subnet. Slow down enough to calculate the block size correctly.

KKey Concepts to Remember

  • CIDR notation defines the prefix length.
  • Block size helps identify subnet boundaries.
  • Network and broadcast addresses are not usable hosts in normal IPv4 subnets.
  • The required host count determines the smallest suitable subnet.

TExam Day Tips

  • Write the block size before choosing the subnet.
  • Check whether the question asks for hosts, subnets or a specific address range.
  • Do not confuse /24, /25, /26 and /27 host counts.

Key takeaway

Count usable hosts — not total addresses — and remember that the network and broadcast addresses are not available to hosts in standard IPv4 subnets.

Real-world example

How this comes up in practice

A network engineer segments a warehouse floor into three subnets: 20 scanners, 5 printers, and 2 management hosts. Picking the wrong mask wastes addresses or leaves too few usable hosts. Exam questions test whether you can apply CIDR notation, calculate block size, and identify the correct usable-host range for a given prefix.

What to study next

Got this wrong? Here's your next step.

Review block sizes, usable host formulas (2^n − 2), and how to find network and broadcast addresses for /24 through /30. Then practise related 1Z0-811 subnetting questions on CIDR, address ranges, and subnet selection.

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.

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?

Primitives, Strings and Operators — This question tests Primitives, Strings and Operators — CIDR notation defines the prefix length..

What is the correct answer to this question?

The correct answer is: Add parentheses: if ((x & y) == 1) { ... } — In Java, the bitwise AND operator & has lower precedence than the equality operator ==. Therefore, x & y == 1 is parsed as x & (y == 1), which performs a boolean comparison (y == 1) and then bitwise ANDs x with the boolean result (true = 1, false = 0), not what was intended. The fix is to add parentheses: (x & y) == 1. Option A corrects the precedence. Option B uses logical AND (&&) which is not bitwise. Option C uses bitwise OR (|) which is not correct for checking both bits set. Option D uses modulo (%), which works for odd check but not for bitmasking in general.

What should I do if I get this 1Z0-811 question wrong?

Review block sizes, usable host formulas (2^n − 2), and how to find network and broadcast addresses for /24 through /30. Then practise related 1Z0-811 subnetting questions on CIDR, address ranges, and subnet selection.

Are there clue words in this question I should notice?

Yes — watch for: "least", "never". You want the option with minimum overhead, fewest steps, or lowest impact — not the most feature-rich or comprehensive answer.

What is the key concept behind this question?

CIDR notation defines the prefix length.

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 →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 23, 2026

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.

Loading comments…

Sign in to join the discussion.

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.