Prévia do material em texto
Certified Java Programmer Mock Exam 12
d. Prints: 10
e. Prints: 1 3 4
f. Prints: 8
g. Prints: 1 3 5
h. Prints: 9
i. Runtime error.
j. Compiler error.
k. None of the Above
Question 11
class M {
static int m(int i) {
System.out.print(i + ", ");
return i;
}
public static void main(String s[]) {
int i=0;
int j = m(++i) + m(++i) * m(++i) % m(++i) + m(++i);
System.out.print(j%5);
}
}
What is the result of attempting to compile and run the above program?
a. Prints: 1,2,3,4,5,1
b. Prints: 1,2,3,4,5,2
c. Prints: 1,2,3,4,5,3
d. Prints: 1,2,3,4,5,4
e. Prints: 1,2,3,4,5,5
f. Runtime error
g. Compiler error
h. None of the above
Question 12
1. class Purple {
2. public static void main (String []args) {
3. int[] i = {1,2,3};
4. Object obj = i;
5. i = obj;
6. }
7. }
What is the result of attempting to compile and run the above program?
a. Compiler error at line 2.
b. Runtime error at line 2.
c. Compiler error at line 3.
d. Runtime error at line 3.
e. Compiler error at line 4.
f. Runtime error at line 4.
g. Compiler error at line 5.
h. Runtime error at line 5.
i. Compiles and runs without error.
Question 13
class A {}
class B extends A {}
class C extends B {
static void m(A x, A y) {System.out.print("AA");}
static void m(A x, B y) {System.out.print("AB");}
static void m(B x, A y) {System.out.print("BA");}
static void m(B x, B y) {System.out.print("BB");}
public static void main(String[] args) {
A a;
B b;
m(null,null);
m(a=null,b=null);
m(b, a);
}
}
What is the result of attempting to compile and run the above program?
a. Prints: BBABAB
b. Prints: BBABBA
c. Prints: BBBBAB
d. Prints: BBBBBA
e. Prints: BBBBBB
f. Compiler error.
g. Runtime error.
h. None of the Above
Question 14
class S {