1Z0-808 · Question #66
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 log4:true. Option B is correct because both expressions evaluate to true. For log3, both operands of && are true - 5.0 != 6.0 is true and 4 != 5 is true - so true && true = true. For log4, the || operator only needs one operand to be true: 4 != 4 is false, but 4 == 4 is true, so false ||…
Question
Options
- Alog3:false log4:true
- Blog3:true log4:true
- Clog3:true log4:false
- Dlog3:false log4:false
How the community answered
(46 responses)- A2% (1)
- B80% (37)
- C4% (2)
- D13% (6)
Explanation
Option B is correct because both expressions evaluate to true. For log3, both operands of && are true - 5.0 != 6.0 is true and 4 != 5 is true - so true && true = true. For log4, the || operator only needs one operand to be true: 4 != 4 is false, but 4 == 4 is true, so false || true = true. Options A and D are wrong because they claim log3 is false - a mistake made by confusing != (not-equal) with ==; both comparisons in log3 are clearly not-equal, so both are true. Option C is wrong because it claims log4 is false, which would require both sides of || to be false - but 4 == 4 is always true.
Memory tip: Think of && as a strict bouncer (both must be true) and || as a lenient one (either can be true). For !=, ask yourself "are these different?" - if yes, the result is true.
Topics
Community Discussion
No community discussion yet for this question.