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)- A13% (6)
- B9% (4)
- C2% (1)
- D76% (34)
Community Discussion
No community discussion yet for this question.