Skip to content
Sharp

Core Java · interview question

In the following code, which line will print to the console when an exception occurs in processOrder()?

Multiple choiceMediumchapter-6-curatedpremiumcore-javacode-reading-with-exceptions
java
try { processOrder(); System.out.println("Order processed."); } catch (Exception e) { System.out.println("Processing failed."); } finally { System.out.println("Order processing completed."); }
Choose one answer
Answer and explanation

Correct answer

D. Processing failed.

Why

When an exception is thrown in processOrder(), the catch block will handle it, printing 'Processing failed.' before the finally block executes.

Test yourself on Core Java

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

Start free test
All Core Java questions →