🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Control Flow: all 10 questions

Quiz: Java Control Flow · Question 10 of 10

What happens with int x = 3; if (x = 5) { ... } in Java?

What happens with int x = 3; if (x = 5) { ... } in Java?

  1. A.The condition is true because 5 is not zero
  2. B.x is compared with 5
  3. C.Compile error: an int cannot be used as a boolean condition
  4. D.The condition is false
Answer & explanation

Correct answer: Compile error: an int cannot be used as a boolean condition

Unlike C, Java requires a boolean in an if. Use == to compare.

Can you get the rest right without peeking?

Take the timed Quiz: Java Control Flow quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →