Question

What is the output of the following Java code?     public class Test {         public static void main(String[] args) {             try {                 int[] arr = {1, 2, 3};                 System.out.println(arr[5]);             } catch (Exception
e) {                 System.out.println("Caught: " + e.getClass().getSimpleName());             } finally {                 System.out.println("Cleanup");             }         }     }

A Caught: ArrayIndexOutOfBoundsException Cleanup
B Cleanup Caught: ArrayIndexOutOfBoundsException
C Compilation error, since Exception cannot catch runtime array errors
D Caught: ArrayIndexOutOfBoundsException (finally does not execute due to the exception)
E Program crashes with no output before termination
Practice Next

Hey! Ask a query