Multiple choice technology programming languages

Given:class Demo { static String s = ""; public static void main(String[] args) { try { throw new Exception(); } catch (Exception e) { try { try { throw new Exception(); } catch (Exception ex) { s += "ic"; } throw new Exception(); } catch (Exception x) { s += "mc"; } finally { s += "mf"; } } finally { s +="of"; } System.out.println(s);} }What is the result?

  1. -ic of

  2. -mf of

  3. Compilation failure

  4. -ic mf of

  5. -ic mc mf of

  6. -ic mc of mf

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

The nested try-catch-finally blocks execute in sequence: Inner try throws, caught by 'ex' -> 'ic' appended. Then throws new Exception, caught by outer catch 'x' -> 'mc' appended. Outer finally executes -> 'mf' appended. Outermost finally executes -> 'of' appended. The sequence is ic (inner catch), mc (middle catch), mf (middle finally), of (outer finally) = '-ic mc mf of'.