Prévia do material em texto
Certified Java Programmer Mock Exam 33
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. }
9.
10. class B {
11. public static void main(String[] args) {
12. A a = new A();
13. a.m1();
14. a.m2();
15. a.m3();
16. a.m4();
17. }
18. }
Assume that the above code appears in a single file named A.java. 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 13.
c. Compiler error at line 14.
d. Compiler error at line 15.
e. Compiler error at line 16.
f. None of the Above
Question 2
class Basics {
int x = 1;
int y = 2;
public static void main (String[] args) {
System.out.println(x+y);
}
}
What is the result of attempting to compile and run the above program?
a. Prints: 1 2
b. Prints: 12
c. Prints: 3
d. Run time Exception
e. Compiler Error
f. None of the Above
Question 3
1. public class Basics {}
2. public class Basics2 {}
3. public class Basics3 {}
4. public class Basics4 {}
Assuming these class definitions are contained in a file named Basics.java, what is the result of attempting to compile the contents of the file?
a. Compiler error at line 1.
b. Compiler error at line 2.
c. Compiler error at line 3.
d. Compiler error at line 4.
e. None of the Above
Question 4
Which of the following modifiers can not be used with the abstract modifier in a method declaration?
a. final
b. private
c. protected
d. public
e. static
f. synchronized
g. native
h. strictfp
i. None of the above.
Question 5
class A {
public static void main(String[] args) {
int[] a1 = {1,2,3};
int []a2 = {4,5,6};
int a3[] = {7,8,9};
System.out.print(a1[1]+","+a2[1]+","+a3[1]);
}
}
What is the result of attempting to compile and run the above program?
a. Prints: 12
b. Prints: 15
c. Prints: 18
d. Prints: 1,4,7
e. Prints: 2,5,8
f. Prints: 3,6,9
g. Compiler Error.