Presuming all required import statements are in place, which lines of the following code will cause a compilation error?

1: class A {
2:    void m1() {throw new ArithmeticException();}
3:    void m2() {throw new ClassCastException();}
4:    void m3() {throw new IllegalArgumentException();}
5:    void m4() {throw new IndexOutOfBoundsException();}
6:    void m5() {throw new NullPointerException();}
7:    void m6() {throw new SecurityException();}
8: }
Explanation
All listed exceptions extend "RuntimeException" class, hence all of them are Unchecked Exceptions. They can be declared in the method signature (using throws) but this is not required for compilation.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes