nerdexam
Oracle

1Z0-829 · Question #7

1Z0-829 Question #7: Real Exam Question with Answer & Explanation

The correct answer is D. false 1. Tracing the key values step by step: a = 2, b = ~2 = -3 (bitwise NOT in two's complement: ~n = -(n+1)), c = 2 ^ -3 = -1 (any value XOR its complement equals all-ones = -1) For d: the single & is non-short-circuit - both sides always evaluate. a < b → 2 < -3 → false; a > c++ → 2 >

Handling date, time, text, numeric and boolean values

Question

Given the code fragment: int a = 2; int b = ~a; int c = a^b; boolean d = a < b & a > c++; boolean e = a > b && a > c++; System.out.println(d + " " + c); System.out.println(e + " " + c); What is the result?

Options

  • Afalse 1
  • Bfalse 2
  • Ctrue 1
  • Dfalse 1
  • Etrue 1
  • Ffalse 0

Explanation

Tracing the key values step by step:

  • a = 2, b = ~2 = -3 (bitwise NOT in two's complement: ~n = -(n+1)), c = 2 ^ -3 = -1 (any value XOR its complement equals all-ones = -1)
  • For d: the single & is non-short-circuit - both sides always evaluate. a < b2 < -3false; a > c++2 > -1true, and c post-increments to 0. So d = false & true = false, with c = 0.
  • For e: the && short-circuits only when the left side is false - since a > b2 > -3true, the right side still evaluates: a > c++2 > 0true, c post-increments to 1. So e = true, with c = 1.
  • First println: false 1. Second println: true 1. Option D is correct.

Why distractors fail: Options showing c = 2 or c = 0 miscount the post-increments - both c++ expressions execute because & never short-circuits and && only skips the right side when the left is false (not true). Options showing d = true misread 2 < -3 as true, forgetting that ~2 is -3, not 3.

Memory tip: Think of &/| as "bitwise bulldozers" - they plow through both sides no matter what. &&/|| are "lazy logical" - they bail early only when the first operand already decides the outcome (false && or true ||).

Topics

#bitwise operators#logical operators#short-circuit evaluation#post-increment

Community Discussion

No community discussion yet for this question.

Full 1Z0-829 Practice