nerdexam
GIAC

GSSP-JAVA · Question #100

Wilbert works as a Software Developer for Wintos Inc. He writes the following code. 1. public class tcf 2. { 3. public static void main(String[] args) 4. { 5. try 6. { 7. int x = 5 / 0; 8…

The correct answer is C. It will compile and print Within catch and Within finally as the output. See the full explanation below for the reasoning.

Question

Wilbert works as a Software Developer for Wintos Inc. He writes the following code. 1. public class tcf 2. { 3. public static void main(String[] args) 4. { 5. try 6. { 7. int x = 5 / 0; 8. System.exit(0); 9. } 10. catch(ArithmeticException e) 11. { 12. System.out.println("Within catch"); 13. } 14. finally 15. { 16. System.out.println("Within finally"); 17. } 18. } 19. } What will happen when he tries to compile and execute the code?

Options

  • AIt will compile and print Within catch as the output.
  • BIt will compile and execute successfully but will not print anything.
  • CIt will compile and print Within catch and Within finally as the output.
  • DIt will compile and print Within finally as the output.

How the community answered

(17 responses)
  • A
    12% (2)
  • B
    6% (1)
  • C
    76% (13)
  • D
    6% (1)

Community Discussion

No community discussion yet for this question.

Full GSSP-JAVA Practice