Skip to content
Sharp

Exceptions · interview question

Consider the following code snippet. What will happen if the input is null?

Multiple choiceMediumchapter-6-curatedpremiumexceptionsexceptions-basics
java
public void processOrder(String order) {
    System.out.println(order.toUpperCase());
}
Choose one answer
Answer and explanation

Correct answer

B. A NullPointerException will be thrown.

Why

If the input is null, attempting to call a method on it will result in a NullPointerException, as null references cannot be dereferenced.

Test yourself on Exceptions

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

Start free test
All Exceptions questions →