Prévia do material em texto
Certified Java Programmer Mock Exam 16
4. class Sub extends Base implements I2 {}
5.
6. class Orange {
7. public static void main(String args[]) {
8. Base base = new Base();
9. I1 i1 = base;
10. Sub sub = (Sub)base;
11. }
12. }
What is the result of attempting to compile and run the above program?
a. Compiler error at line 9.
b. Runtime error at line 9.
c. Compiler error at line 10.
d. Runtime error at line 10.
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