nerdexam
Oracle

1Z0-811 · Question #42

Given the code fragment: System.out.println(10 == 10 && ! (5 != 5)); System.out.println(10 < 8 | | 10 > 2); What is the result?

The correct answer is A. true true. Option A is correct because both expressions evaluate to true. In line 1, 10 == 10 is true, and 5 != 5 is false, so !(false) becomes true - making true && true yield true. In line 2, 10 < 8 is false but 10 > 2 is true, and since || (OR) only needs one operand to be true, the…

Data Types and Operators

Question

Given the code fragment: System.out.println(10 == 10 && ! (5 != 5)); System.out.println(10 < 8 | | 10 > 2); What is the result?

Options

  • Atrue true
  • Btrue false
  • Cfalse false
  • Dfalse true

How the community answered

(24 responses)
  • A
    92% (22)
  • B
    4% (1)
  • D
    4% (1)

Explanation

Option A is correct because both expressions evaluate to true. In line 1, 10 == 10 is true, and 5 != 5 is false, so !(false) becomes true - making true && true yield true. In line 2, 10 < 8 is false but 10 > 2 is true, and since || (OR) only needs one operand to be true, the result is true.

Why distractors fail: Options C and D require the first expression to be false, which can't happen since 10 == 10 is always true and double-negation on a false value gives true. Option B requires the second expression to be false, but || returns false only when both sides are false - 10 > 2 saves it.

Memory tip: For && (AND), think "both must win"; for || (OR), think "one winner is enough" - and always work the innermost parentheses and ! (NOT) operators first before combining with && or ||.

Topics

#boolean operators#comparison operators#logical expressions#operator precedence

Community Discussion

No community discussion yet for this question.

Full 1Z0-811 Practice