Join Examsbook
1033 0

Q: What is the output after compile and run the following code ? int Output = 10;boolean b = false;if((b == true) && ((Output += 10) == 20)){ System.out.println("We are equal " + Output);}else{ System.out.println("Not equal! " + Output);}

  • 1
    Compilation and output of "We are equal 10"
  • 2
    Compilation and output of "Not equal! 10"
  • 3
    Compilation error, attempting to perform binary comparison on logical data type
  • 4
    Compilation and output of "Not equal! 20"
  • Show AnswerHide Answer
  • Workspace

Answer : 2. "Compilation and output of "Not equal! 10""
Explanation :

Answer: B) Compilation and output of "Not equal! 10" Explanation: The output will be "Not equal! 10". Please note that && is logical AND operator. If first operand before (&&) is false then the other operand will not be evaluated. This illustrates that the Output +=10 calculation was never performed because processing stopped after the first operand was evaluated to be false. If you change the value of b1 to true, processing occurs as you would expect and the output would be "We are equal 20".

Are you sure

  Report Error

Please Enter Message
Error Reported Successfully