1Z0-803 · Question #81
What is the result? boolean log3 = ( 5.0 != 6.0) && ( 4 != 5); boolean log4 = (4 != 4) || (4 == 4); System.out.println("log3:"+ log3 + \nlog4" + log4);
The correct answer is B. log3:true. This question assesses knowledge of Java's relational and logical operators and how they are evaluated.
Question
What is the result? boolean log3 = ( 5.0 != 6.0) && ( 4 != 5); boolean log4 = (4 != 4) || (4 == 4); System.out.println("log3:"+ log3 + \nlog4" + log4);
Options
- Alog3:false
- Blog3:true
- Clog3:true
- Dlog3:false
How the community answered
(40 responses)- A8% (3)
- B88% (35)
- C3% (1)
- D3% (1)
Why each option
This question assesses knowledge of Java's relational and logical operators and how they are evaluated.
This option is incorrect because `(5.0 != 6.0)` is `true` and `(4 != 5)` is `true`, making `log3` result in `true` when combined with `&&`.
For `log3`, `(5.0 != 6.0)` is `true` and `(4 != 5)` is also `true`. Since both operands of the logical AND (`&&`) are `true`, `log3` evaluates to `true`. For `log4`, `(4 != 4)` is `false` and `(4 == 4)` is `true`. Since one operand of the logical OR (`||`) is `true`, `log4` evaluates to `true`. The output is therefore `log3:true\nlog4:true`.
While `log3:true` is correct, this option might imply an incorrect value for `log4` or represent an incomplete output.
This option is incorrect because the evaluation of `(5.0 != 6.0) && (4 != 5)` correctly yields `true`, not `false`.
Concept tested: Java relational and logical operators
Topics
Community Discussion
No community discussion yet for this question.