Question
Which of the following correctly handles multiple
exceptions in Java?Solution
In Java, a single try block can handle multiple exceptions by attaching multiple catch blocks. Each catch block specifies a distinct exception type. The exception hierarchy determines the order of catch blocks—child exceptions must precede parent exceptions. Example: try {   int a = 5 / 0;  // ArithmeticException   int[] arr = new int[2];   System.out.println(arr[3]); // ArrayIndexOutOfBoundsException } catch (ArithmeticException e) {   System.out.println("Arithmetic Exception caught"); } catch (ArrayIndexOutOfBoundsException e) {   System.out.println("Array Index Out of Bounds Exception caught"); } catch (Exception e) {   System.out.println("Generic Exception caught"); } ________________________________________ Why Other Options Are Incorrect: 1. Separate try blocks for each exception: This is inefficient and makes code less readable. A single try block with multiple catch blocks is the recommended approach. 2. Nesting try blocks within each other: This is not a standard practice unless the logic explicitly demands it. It can lead to convoluted and hard-to-maintain code. 3. Single catch block for all exceptions: While possible, this is a poor practice as it does not differentiate exception types, leading to less precise error handling. 4. Writing the exception type as a string: Java’s catch block requires exception classes, not strings, for type checking.
Which instrument is used to measure the moisture content in the air?
A particle is fired with initial speed 30 m/s and lands back at same horizontal level. If its horizontal range is equal to 4.5 times the vertical height...
A body is projected upwards with an initial velocity u . At the highest point, what is its acceleration? Â
In a spring-block system executing SHM, at displacement x= A/2, the ratio of kinetic to potential energy is:
A charged particle oscillates about its mean equilibrium position with a frequency of 105 Hz. What is the frequency of the electromagnetic wa...
Which of the following is the energy quantum of radiation?
A 4 cm wire carrying a current of 15 A is placed inside a solenoid perpendicular to its axis. The magnetic field inside the solenoid is given to be 0.27...
An ant can see objects all around it due to the presence of which type of eyes?
The pitch of a sound is primarily determined by which of the following?
An electron in a hydrogen atom de-excites from the 4th to the 2nd level. The wavelength of emitted photon falls in which series?