}
}
a. The program displays 1 2 3 4 5.
b. The program displays 1 2 3 4 5 and then raises an ArrayIndexOutOfBoundsException.
c. The program displays 5 4 3 2 1.
d. The program displays 5 4 3 2 1 and then raises an ArrayIndexOutOfBoundsException.
#
32. Analyze the following code:
public class Test1 {
public static void main(String[] args) {
xMethod(new double[]{3, 3});
xMethod(new double[5]);
xMethod(new double[3]{1, 2, 3});
}
public static void xMethod(double[] a) {
System.out.println(a.length);
}
}
a. The program has a compile error because xMethod(new double[]{3, 3}) is incorrect.
b. The program has a compile error because xMethod(new double[5]) is incorrect.
c. The program has a compile error because xMethod(new double[3]{1, 2, 3}) is incorrect.
d. The program has a runtime error because a is null.
#
11. What would be the result of attempting to compile and run the following code?
public class Test {
public static void main(String[] args) {
double[] x = new double[]{1, 2, 3};
System.out.println(“Value is ” + x[1]);
}
}
a. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by
{1, 2, 3}.
b. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by
new double[3]{1, 2, 3};
c. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by
new double[]{1.0, 2.0, 3.0};
d. The program compiles and runs fine and the output “Value is 1.0″ is printed.
e. The program compiles and runs fine and the output “Value is 2.0″ is printed.
#
30. Do the following two programs produce the same result?
Program I:
public class Test {
public static void main(String[] args) {