A

Admin • 830.42K Points
Coach

Q. What is the result of the following code snippet?

try {
throw new NullPointerException();
} catch (ArithmeticException e) {
System.out.println("Arithmetic Exception!");
} catch (NullPointerException e) {
System.out.println("NullPointerException!");
}

  • (A) NullPointerException!
  • (B) Compilation error
  • (C) Runtime exception
  • (D) Arithmetic Exception!
  • Correct Answer - Option(A)
  • Views: 31
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
In the given code snippet, a NullPointerException is explicitly thrown within the try block. When an exception is thrown, the Java runtime looks for a catch block that matches the type of the thrown exception.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.