nerdexam
GIAC

GSSP-JAVA · Question #128

Rachel works as a Software Developer for Vivanet Inc. She writes the following code using Java. class catchexcp {public static void metha() {int x=4/0;System.out.print("Caught exception");} public…

The correct answer is F. It will compile and execute and will display Caught ArithmeticException ReCaught. See the full explanation below for the reasoning.

Question

Rachel works as a Software Developer for Vivanet Inc. She writes the following code using Java. class catchexcp {public static void metha() {int x=4/0;System.out.print("Caught exception");} public static void main(String args[]) {try{metha();}catch(ArithmeticException ae){System.out.print("Caught ArithmeticException");}finally{try{metha();}catch(ArithmeticException ae){System.out.print("ReCaught ArithmeticException");}}}} What will happen when she tries to compile and execute the code?

Options

  • AIt will compile and execute and will display ReCaught ArithmeticException.
  • BIt will not compile.
  • CIt will compile but will throw an exception at runtime.
  • DIt will compile and execute and will display Caught exception Caught ArithmeticException
  • EIt will compile and execute and will display Caught exception ReCaught
  • FIt will compile and execute and will display Caught ArithmeticException ReCaught

How the community answered

(39 responses)
  • A
    3% (1)
  • B
    10% (4)
  • C
    5% (2)
  • D
    3% (1)
  • F
    79% (31)

Community Discussion

No community discussion yet for this question.

Full GSSP-JAVA Practice