Prévia do material em texto
Certified Java Programmer Mock Exam 31
h. None of the above
Question 12
class C {
static int m(int i) {
System.out.print(i + ", ");
return i;
}
public static void main(String s[]) {
int i = 1;
m(m(++i) - m(i++) + m(-i) * m(~i));
}
}
What is the result of attempting to compile and run the above program?
a. Prints: 2, 2, -3, -4, 8,
b. Prints: 2, 2, -3, -4, 12,
c. Prints: 2, 3, -3, -4, 7,
d. Prints: 1, 1, 1, 1, 0,
e. Prints: 2, 2, -2, -2, 4,
f. Prints: 2, 3, -2, -2, 3,
g. Prints: -1, -2, 2, 2, 0,
h. Runtime error
i. Compiler error
j. None of the above
Question 13
1. interface I1 {}
2. interface I2 {}
3. class Base implements I1 {}
4. class Sub extends Base implements I2 {}
5. class Yellow {
6. public static void main(String args[]) {
7. Base base = new Sub();
8. I1 i1 = base;
9. Sub sub = (Sub)base;
10. I2 i2 = (Sub)base;
11. }
12. }
What is the result of attempting to compile and run the above program?
a. Compiler error at line 7.
b. Runtime error at line 7.
c. Compiler error at line 8.
d. Runtime error at line 8.
e. Compiler error at line 9.
f. Runtime error at line 9.
g. Compiler error at line 10.
h. Runtime error at line 10.
i. Compiles and runs without error.
Question 14
class A {}
class B {
static void m(Object x) {System.out.print("Object");}
static void m(String x) {System.out.print("String");}
public static void main(String[] args) {
m(null);
}
}
What is the result of attempting to compile and run the above program?
a. Prints: Object
b. Prints: String
c. Compiler error.
d. Runtime error.
e. None of the Above
Question 15
1. class White {
2. public static void main(String args[]) {
3. int[] i = {1,2,3,4,5};
4. long[] l1 = new long[5];
5. long []l2 = l1;
6. long l3[] = (long[])i;
7. long l4[] = new long[5];
8. l4[1] = i[1];
9. }
10. }
What is the result of attempting to compile and run the above program?
a. Compiler error at line 3.
b. Runtime error at line 3.