Given: What is the result?
A.
0 Done
B.
Third Exception
C.
Done Third Exception
D.
First Exception Done
E.
Second Exception
Given: What is the result?
A.
0 Done
B.
Third Exception
C.
Done Third Exception
D.
First Exception Done
E.
Second Exception
B
D, b/s dispResult was handle exception and not throws exception
Technically, as is, none of these answers are correct. Notwithstanding capitalization, the answer is B because of an unhandled ArrayIndexOutOfBoundsException due to num[2]. If num[2] were a num[0] or num[1], then it would print…
first exception
Done
If num[2] were a num[0] or num[1], then it would print…
first exception. NO, see below:
Adjusted code question:
public class Test {
static void dispResult(int[] num) {
try {
System.out.println(num[1]) / (num[1] – num[0]));
} catch (ArithmeticException e) {
System.err.println(“first exception”);
}
System.out.println(“Done”);
}
public static void main(String[] args) {
try {
int[] arr = {100, 100};
dispResult(arr);
} catch (IllegalArgumentException e) {
System.err.println(“second exception”);
} catch (Exception e) {
System.err.println(“third exception”);
}
}
}
Output:
run:
third exception
BUILD SUCCESSFUL (total time: 1 second)
b
tested
package javaapplication3;
class DBConfiguration {
String user;
String password;
}
public class Test {
static void dispResult(int[] num){
try{
System.out.println(num[1]/(num[1]-num[2]));
}
catch (ArithmeticException e){
System.err.println(“first”);
}
System.err.println(“done”);
}
public static void main(String[] args){
try {
int[] arr = {100,100};
dispResult(arr);
}
catch (IllegalArgumentException e){
System.err.println(“second”);
}
catch (Exception e){
System.err.println(“third”);
}
}
}