What will be the output of the following Java code?class exception_handling {public static void main(String args[]) {try {int a = args.length;int b = 10 / a;System.out.print(a);try { if (a == 1) a = a / a - a; if (a == 2) { int []c = {1}; c[8] = 9; }}catch (ArrayIndexOutOfBoundException e) {System.out.println("TypeA");}catch (ArithmeticException e) {System.out.println("TypeB");}}}Note: Execution command line: $ java exception_handling one two

🎲 Try a Random Question  |  Total Questions in Quiz: 61  |  🧠 Study this quiz with Flashcards
This question is part of a full practice quiz:
Java Basics Practice Test: Exception Handling — practice the complete quiz, review flashcards, or try a random question.

Quiz on basics of exception handling, exception types like throw, throws and nested try. Java exception handling is a mechanism for handling and responding to runtime errors. Exceptions are events that occur during the execution of a program that disrupt the normal flow of the program. Exception handling allows developers to detect and handle these errors in a controlled manner, preventing the program from crashing.   There are two main types of exceptions in Java: checked exceptions and unchecked exceptions. Checked exceptions are exceptions that must be explicitly handled by the... Show more

What will be the output of the following Java code?<br>class exception_handling <br>{<br>public static void main(String args[]) <br>{<br>try <br>{<br>int a = args.length;<br>int b = 10 / a;<br>System.out.print(a);<br>try <br>{<br> if (a == 1)<br> a = a / a - a;<br> if (a == 2) <br> {<br> int []c = {1};<br> c[8] = 9;<br> }<br>}<br>catch (ArrayIndexOutOfBoundException e) <br>{<br>System.out.println("TypeA");<br>}<br>catch (ArithmeticException e) <br>{<br>System.out.println("TypeB");<br>}<br>}<br>}<br><br>Note: Execution command line: $ java exception_handling one two