class Test { public static void main(String[] args) { try { int a[]= {1, 2, 3, 4}; for (int i = 1; i <= 4; i++) { System.out.println ("a[" + i + "]=" + a[i] + "\n"); } } catch (Exception e) { System.out.println ("error = " + e); } catch (ArrayIndexOutOfBoundsException e) { System.out.println ("ArrayIndexOutOfBoundsException"); } } } |
chevron_right
filter_none
(A) Compiler error
(B) Run time error
(C) ArrayIndexOutOfBoundsException
(D) Error Code is printed
(E) Array is printed
Answer: (A)
Explanation: ArrayIndexOutOfBoundsException has been already caught by base class Exception. When a subclass exception is mentioned after base class exception, then error occurs.
Quiz of this Question
Recommended Posts:
- Java | Exception Handling | Question 1
- Java | Exception Handling | Question 2
- Java | Exception Handling | Question 3
- Java | Exception Handling | Question 4
- Java | Exception Handling | Question 8
- Java | Exception Handling | Question 7
- Java | Exception Handling | Question 8
- Output of Java program | Set 12(Exception Handling)
- Nested try blocks in Exception Handling in Java
- Exception Handling with Method Overriding in Java
- Version Enhancements in Exception Handling introduced in Java SE 7
- C++ | Exception Handling | Question 1
- C++ | Exception Handling | Question 2
- C++ | Exception Handling | Question 3
- C++ | Exception Handling | Question 4
- C++ | Exception Handling | Question 5
- C++ | Exception Handling | Question 6
- C++ | Exception Handling | Question 7
- C++ | Exception Handling | Question 8
- C++ | Exception Handling | Question 9

