What will be the output of the following Java code?class exception_handling {public static void main(String args[]){try {int a = 1;int b = 10 / a;try { if (a == 1) a = a / a - a; if (a == 2) { int c[] = {1}; c[8] = 9; }}finally {System.out.print("A");}}catch (Exception e) {System.out.println("B");}}}

🎲 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 = 1;<br>int b = 10 / 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>finally <br>{<br>System.out.print("A");<br>}<br>}<br>catch (Exception e) <br>{<br>System.out.println("B");<br>}<br>}<br>}