Prévia do material em texto
Certified Java Programmer Mock Exam 13
public static void main(String args[]) {
byte b = -1,c,d; // 1
c = (byte)(b >>> 1); // 2
d = (byte)(b >>> 25); // 3
System.out.print(c+","+d);
}
}
What is the result of attempting to compile and run the above program?
a. Prints: 127,0
b. Prints: 0,127
c. Prints: -1,0
d. Prints: -1,127
e. Prints: -1,-1
f. Prints: 127,127
g. Runtime error
h. Compiler error
i. None of the above
Question 15
import java.io.Serializable;
1. class Blue {
2. public static void main (String args[]) {
3. int[] i = {1,2,3};
4. Serializable s = i;
5. i = (int [])s;
6. }
7. }
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.
c. Compiler error at line 4.
d. Runtime error at line 4.
e. Compiler error at line 5.
f. Runtime error at line 5.
g. Compiles and runs without error.
Question 16
1. interface I1 {}
2. interface I2 {}
3. class Base implements I1 {}
4. class Sub extends Base implements I2 {}
5.
6. class Red {
7. public static void main(String args[]) {
8. Sub s1 = new Sub();
9. I2 i2 = s1;
10. I1 i1 = s1;
11. Base base = s1;
12. Sub s2 = (Sub)base;
13. }
14. }
What is the result of attempting to compile and run the above program?
a. Compiler error at line 9.
b. Compiler error at line 10.
c. Compiler error at line 11.
d. Compiler error at line 12.
e. Runtime error.
f. Compiles and runs without error.
Question 17
class L {
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
int a = 1;
long b = 2;
System.out.print(m(a)+","+ m(b));
}
}
What is the result of attempting to compile and run the above program?
a. Prints: float,float
b. Prints: float,double
c. Prints: double,float
d. Prints: double,double
e. Compiler error.
f. Runtime error.
g. None of the Above
Question 18