m in try block
Exception in thread "main" java.lang.ClassCastException // why does this prints before printing next line i.e. before array index out of bounds
array index out of bounds
i am always executed
Java Result: 1
Your System.out.println calls are written to standard output.
The Exception in thread "main" java.lang.ClassCastException message is written to standard error.
Because you are writing to different output streams and the i/o is asynchronous there is no guarantee of the order in which the messages will be written.
If you want to guarantee the order, change the System.out.println calls to System.err.println calls