Leave a Reply 6

Your email address will not be published. Required fields are marked *


noname

noname

D, b/s dispResult was handle exception and not throws exception

Ryan

Ryan

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

renko

renko

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)

xxx

xxx

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”);

}
}

}