Which of the following strings are printed as output of the

Which of the following strings are printed as output of the following program? Note that you may use Eclipse to check your answer! public class TestExceptions {public static void main(String[] args) {int[] numbers = new int[10]; try {numbers[11] = 1; System.out.println(\"Success!\");} catch (ArraylndexOutOfBoundsException ex) {System.out.println(\"lndex was out of bounds\");} catch (Exception ex) {System.out.println(\"Something went wrong\");} System. out.printlnf\'Done\")}} Success Index was out of bounds Something went wrong Not printed Printed

Solution

Answer:

Below two statements will be printed once we run this program

Index was out of bounds

Done

Explanation: We have created an integer array numbers with size 10. it means indexes are available from 0 to 9.

But we are trying to assigning a value 1 to index 11 which is not available in array numbers. So it will throw an exception ArrayIndexOutOfBounds that will be caught in catch block and will display \"Index was out of bounds\". Since we mentioned statement Done after catch block and we have already handled that exception so \"Done\" also will print.

 Which of the following strings are printed as output of the following program? Note that you may use Eclipse to check your answer! public class TestExceptions

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site