🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Exception Handling: all 10 questions

Quiz: Java Exception Handling · Question 10 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        try {
            int n = Integer.parseInt("12a");
            System.out.println(n);
        } catch (NumberFormatException e) {
            System.out.println("not a number");
        }
    }
}
  1. A.12
  2. B.0
  3. C.not a number
  4. D.Compile error
Answer & explanation

Correct answer: not a number

"12a" is not a valid integer, so parseInt throws NumberFormatException, an unchecked exception.

Can you get the rest right without peeking?

Take the timed Quiz: Java Exception Handling quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →