Skip to content
Sharp

Core Java · interview question

Consider the code snippet below. What will be the output when the divide method is called with a divisor of 0?

Multiple choiceMediumchapter-6-curatedpremiumcore-javathrow-throws-and-propagation
java
public int divide(int a, int b) { return a / b; }
Choose one answer
Answer and explanation

Correct answer

B. An ArithmeticException will be thrown.

Why

Attempting to divide by zero in Java results in an ArithmeticException being thrown, as this is an illegal operation.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →