Which exception is thrown in Java when a class is not found at runtime?
2025
Which exception is thrown in Java when a class is not found at runtime?
- A.
NullPointerException
- B.
ClassNotFoundException
- C.
IOException
- D.
ArithmeticException
- E.
NoClassDefFoundError
Attempted by 72 students.
Show answer & explanation
Correct answer: B
Correct answer: ClassNotFoundException.
ClassNotFoundException is thrown when Java tries to load a class by name and cannot find it on the classpath. It is commonly seen with reflective loading such as Class.forName().
Loading lesson…