Multiple choice technology programming languages

class Plane { static String s = "-"; public static void main(String[] args) { new Plane().s1(); System.out.println(s); } void s1() { try { s2(); } catch (Exception e) { s += "c"; } } void s2() throws Exception { s3(); s += "2"; s3(); s += "2b"; } void s3() throws Exception { throw new Exception(); } }

  1. -

  2. -c

  3. -c2

  4. -2c

  5. -c22b

  6. -2c2b

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

s starts as "-". s1() calls s2(). s2() calls s3() which throws Exception immediately. The statements s += "2" in s2() never execute. s1() catches the exception and executes s += "c". Final value: "-c".