🎙 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 6 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        int a = 0;
        if (a != 0 && 10 / a > 1) {
            System.out.println("big");
        } else {
            System.out.println("safe");
        }
    }
}
  1. A.big
  2. B.ArithmeticException
  3. C.safe
  4. D.Compile error
Answer & explanation

Correct answer: safe

&& short-circuits: a != 0 is false, so 10 / a is never evaluated and there is no division by zero.

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 →