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…
Question
Options
- Atrue true
- Btrue false
- Cfalse false
- Dfalse true
How the community answered
(24 responses)- A92% (22)
- B4% (1)
- D4% (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
Community Discussion
No community discussion yet for this question.