nerdexam
Oracle

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.

Using Operators and Decision Constructs

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)
  • A
    8% (3)
  • B
    88% (35)
  • C
    3% (1)
  • D
    3% (1)

Why each option

This question assesses knowledge of Java's relational and logical operators and how they are evaluated.

Alog3:false

This option is incorrect because `(5.0 != 6.0)` is `true` and `(4 != 5)` is `true`, making `log3` result in `true` when combined with `&&`.

Blog3:trueCorrect

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`.

Clog3:true

While `log3:true` is correct, this option might imply an incorrect value for `log4` or represent an incomplete output.

Dlog3:false

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

#logical operators#relational operators#boolean expressions

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice