nerdexam
GIAC

GSSP-JAVA · Question #31

Dennis works as a Programmer in Broadnet Inc. He writes the following program. 1. public class Ques0307{ 2. public static void main(String[] argv){ 3. int arr[] = {1, 2, 3, 4}; 4. try{ 5. int k = 0…

The correct answer is A. A compile-time error will occur. See the full explanation below for the reasoning.

Question

Dennis works as a Programmer in Broadnet Inc. He writes the following program. 1. public class Ques0307{ 2. public static void main(String[] argv){ 3. int arr[] = {1, 2, 3, 4}; 4. try{ 5. int k = 0; 6. for(; k < 4; k++) 7. arr[k] = arr[k] + 1; 8. System.out.println("try"); 9. } 10. catch(ArrayIndexOutOfBoundsException a){ 11. System.out.println("index " +k +" not found"); 12. } 13. catch(Exception e){ 14. System.out.println("catch1"); 15. } 16. finally{ 17. System.out.println("finally"); 18. } 19. } 20. } What will happen when Dennis attempts to compile and execute the program?

Options

  • AA compile-time error will occur.
  • BThe program will display index 0 not found catch1 finally
  • CThe program will display index 4 not found finally
  • DThe program will display try finally

How the community answered

(28 responses)
  • A
    82% (23)
  • B
    7% (2)
  • C
    4% (1)
  • D
    7% (2)

Community Discussion

No community discussion yet for this question.

Full GSSP-JAVA Practice