Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6) Consider the following code: try { System.out.print(“1”); Statement1 ; System

ID: 3575506 • Letter: 6

Question

6)     Consider the following code:

try {

    System.out.print(“1”);

    Statement1;

    System.out.print(“2”);

    Statement2;

    Statement3;

    System.out.print(“3”);

    Statement4;

}

catch (ExceptionA ex){

   System.out.print(“a”);

}

catch (ExceptionB ex) {

   System.out.print(“b”);

   System.out.print(“d”);

}

catch (ExceptionC ex ) {

System.out.print(“c”);

}

finally {

   System.out.print(“f”);

}

System.out.print(“4”);

Statement5;

Be sure to print out exactly all of the output for each different case below

a) What is printed out if no exceptions are thrown?

b) What is printed out if Statement1 throws ExceptionA?

c) What is printed out if Statement3 throws ExceptionB?

d) What is printed out if Statement4 throws ExceptionC?

Explanation / Answer

a) What is printed out if no exceptions are thrown?------123f4

b) What is printed out if Statement1 throws ExceptionA?------1af4

c) What is printed out if Statement3 throws ExceptionB?----12bdf4

d) What is printed out if Statement4 throws ExceptionC?----123cf4

finally is always executed .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote