Courseiva
Primitives, Strings and OperatorshardMultiple ChoiceObjective-mapped

1Z0-811 Primitives, Strings and Operators Practice Question

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?

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 ==. So x & y == 1 is parsed as x & (y == 1), which first evaluates y == 1 to a boolean, then performs bitwise AND with x, treating true as 1 and false as 0. That's not the intended check. The correct fix is to add parentheses to ensure & is evaluated first: (x & y) == 1. This checks if both numbers have the same least significant bit set (both odd). Option B correctly adds parentheses. Options A, C, and D do not correctly address the bitwise check: A uses modulo which works for odd/even but not general bitmasking; C uses bitwise OR which checks if either bit is set; D uses logical AND which is for booleans, not integers.

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.

  • 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.

About these practice questions

This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.