Prévia do material em texto
Certified Java Programmer Mock Exam 30
e. Compiles and runs without error.
Question 8
1. class Maroon {
2. public static void main (String[] args) {
3. int i=1;
4. short s = 1;
5. long l=1,m=2;
6. i = l + i;
7. l = s + i;
8. }
9. }
What is the result of attempting to compile and run the above program?
a. Compiler error at line 4.
b. Runtime error at line 4.
c. Compiler error at line 5.
d. Runtime error at line 5.
e. Compiler error at line 6.
f. Runtime error at line 6.
g. Compiler error at line 7.
h. Runtime error at line 7.
i. Compiles and runs without error.
Question 9
class Sienna {
static double a;
static float b;
static int c;
static char d;
public static void main(String[] args) {
a = b = c = d = 'a';
System.out.println(a+b+c+d == 4 * 'a');
}
}
What is the result of attempting to compile and run the above program?
a. Prints: true
b. Prints: false
c. Compiler error.
d. Run time error.
e. None of the above.
Question 10
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) {
C c = new C();
m(c, c);
}
}
What is the result of attempting to compile and run the above program?
a. Prints: AA
b. Prints: AB
c. Prints: BA
d. Prints: BB
e. Compiler error.
f. Runtime error.
g. None of the Above
Question 11
class U {
public static void main(String args[]) {
int a = 1;
a += ++a + a++;
System.out.print(a);
}
}
What is the result of attempting to compile and run the above program?
a. Prints: 3
b. Prints: 4
c. Prints: 5
d. Prints: 6
e. Prints: 7
f. Runtime error
g. Compiler error