πŸ“Š JAVA
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!
πŸ’¬ Discuss
βœ… Correct Answer: (A) NullPointerException!

Explanation: 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.

Explanation by: Gopal Sharma
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
130
Total Visits
πŸ“½οΈ
12 mo ago
Published
πŸŽ–οΈ
Gopal Sharma
Publisher
πŸ“ˆ
81%
Success Rate