Multiple choice technology programming languages

class Demo { public static void main(String[] args) { String s = "- " ; try { doMath(args[0]); s += "t "; // line 6 } finally { System.out.println(s += "f "); } } public static void doMath(String a) { int y = 7 / Integer.parseInt(a); } } At commandline if the input is java Demo What will be output?

  1. -f and java.ArrayIndexOutOfBoundsException

  2. -f

  3. ArrayIndexOutOfBoundsException

  4. None of these.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

When 'java Demo' is run with no command-line arguments, args[0] throws ArrayIndexOutOfBoundsException immediately. This is caught by the catch(Exception x) block, setting s='b'. The finally block executes regardless, appending 'f' to s. The output is '-f' followed by the ArrayIndexOutOfBoundsException being printed (since it wasn't caught specifically). The initial try block's 't' is never reached.