Java · Question 26 · Medium

What will be the output of the following Java program?

public class Main {
    public static void main(String[] args) {
        int a = 0;
        boolean b = (a != 0) && (10 / a > 1);
        System.out.println(b);
    }
}
  1. false
  2. true
  3. An ArithmeticException is thrown
  4. Compilation error
Answer and explanation

Answer: A. false

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

Previous: Which Java collection class does NOT allow duplicate elements and keeps… · Next: What will be the output of the following Java program?

Practise java

Try a fresh set of java questions with an explanation after every answer, free and without signing up: Java practice. Or sit a full placement mock test.

More java questions

More technical & programming practice

Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge