Prévia do material em texto
Certified Java Programmer Mock Exam 34
h. Runtime Error.
i. None of the Above.
Question 6
Class A is declared in a file named A.java.
1. package com.dan.chisholm;
2.
3. public class A {
4. public void m1() {System.out.print("A.m1, ");}
5. protected void m2() {System.out.print("A.m2, ");}
6. private void m3() {System.out.print("A.m3, ");}
7. void m4() {System.out.print("A.m4, ");}
8. }
Class C is declared in a file named C.java.
9. package com.dan.chisholm.other;
10.
11. import com.dan.chisholm.A;
12.
13. public class C extends A {
14. public static void main(String[] args) {
15. C c = new C();
16. c.m1();
17. c.m2();
18. c.m3();
19. c.m4();
20. }
21. }
What is the result of attempting to compile and run the above program?
a. Prints A.m1, A.m2, A.m3, A.m3, A.m4,
b. Compiler error at line 16.
c. Compiler error at line 17.
d. Compiler error at line 18.
e. Compiler error at line 19.
f. None of the Above
Question 7
class J {
public static void main(String[] args) {
int[] a2 = {1,2}, a3 = {3,4,5}, a4 = {6,7,8,9}; // 1
int[][] a1 = {a2,a3,a4}; // 2
System.out.print(a1[0][1]+","+a1[1][2]+","+a1[2][3]);
}
}
What is the result of attempting to compile and run the above program?
a. Prints: 14
b. Prints: 16
c. Prints: 1,5,9
d. Prints: 2,4,8
e. Prints: 2,5,9
f. Compile-time Error.
g. Runtime Error.
h. None of the Above.
Question 8
Which of the following is used to force each thread to reconcile its working copy of a variable with the master copy in main memory?
a. abstract
b. final
c. private
d. protected
e. public
f. static
g. synchronized
h. transient
i. volatile
j. native
k. strictfp
l. None of the above.
Question 9
class A {
static byte m1() {
final char c = 'b'-'a';
return c; // 1
}
static byte m2() {
final short s = 2;
return s; // 2
}