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: 3576096 • 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?

Answer:

1234f

b) What is printed out if Statement1 throws ExceptionA?

Answer:

1af4

Once Statement1 throws an exception that will be handled by ExceptionA catch block

c) What is printed out if Statement3 throws ExceptionB?

Answer:

12bdf4

Once Statement3 throws an exception that will be handled by ExceptionB catch block

d) What is printed out if Statement4 throws ExceptionC?

Answer:

123cf4

Once Statement4 throws an exception that will be handled by ExceptionC catch block

finally block will execute irespecive of exception occurred. so f and 4 will always print in all scenarios specified above

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