nerdexam
GIAC

GSSP-JAVA · Question #51

Sam works as a Software Developer for Gentech Inc. He writes the following code. 1. class TryFinallyTest { 2. public static void main(String[] args) { 3. try { 4. int i=15/0; 5…

The correct answer is D. It will give a compile-time error. See the full explanation below for the reasoning.

Question

Sam works as a Software Developer for Gentech Inc. He writes the following code. 1. class TryFinallyTest { 2. public static void main(String[] args) { 3. try { 4. int i=15/0; 5. System.out.println("Testing Try"); 6. } 7. catch(ArithmeticException ae) { 8. System.out.println("Arithmetic exception"); 9. } 10. System.out.println("Correct"); 11. finally { 12. System.out.println("Must execute"); 13. } 14. } 15. } What will happen when he attempts to compile and execute the code?

Options

  • AIt will compile successfully and run with output Arithmetic exception.
  • BIt will compile successfully and run with output Must execute.
  • CIt will compile successfully and run with output Correct.
  • DIt will give a compile-time error.

How the community answered

(45 responses)
  • A
    13% (6)
  • B
    9% (4)
  • C
    2% (1)
  • D
    76% (34)

Community Discussion

No community discussion yet for this question.

Full GSSP-JAVA Practice