SCJP - Page -9

81.)
Given:

1. public class Test {
2. private static int[] x = new int[0];
3. public static void main (String[] args) {
4.System.out.println(x[0]);
5.}
6.}

What is the result?

a. 0
b. null
c. Compilation fails.
d. A NullPointerException is thrown at runtime.
e. An ArrayIndexOutOfBoundsException is thrown at runtime.
82.)
Given:

11. int i = 0, j = 1;
12. if ((i++ == 1) && (j++ == 2)) {
13. i = 42;
14. }
15. System.out.println(“i =” + i + “ , j = “ + j);

What is the result?

a. i = 1, j = 2
b. i = 1, j = 1
c. i = 42, j = 2
d. i = 42, j = 1
e. Compilation fails
83.)
Which satement is true?

a. If only one thread is blocked in the wait method of an object, and another thread executes the
notify method on that same object, then the first thread immediately resumes execution.
b. If a thread is blocked in the wait method of an object, and another thread executes the
notify method on the same object, it is still possible that the first thread might never
resume execution.
c. If a thread is blocked in the wait method of an object, and another thread executes the notify
method on the same object, then the first thread resumes execution as a direct and sole
consequence of the notify call.
d. If two threads are blocked in the wait method of one object, and another thread executes the
notify method on the same object, then the thread that executed the wait call first resumes
execution as a direct and sole consequence of the notify call.
84.)
Given:

1. public class Test {
2. public static void main (String args[]) {
3. System.out.println (6 ^ 3);
4. }
5. }

What is the result?

a. 2
b. 4
c. 5
d. 7
e. 216
f. Compilation fails.
85.)
Given:

1. public class MethodOver {
2. public void setVar(int a, int b, float c) {
3. }
4. }

Which two overload the setVar method? (Choose two.)

a. private void setVar(int a, float c, int b) { }
b. protected void setVar(int a, int b, float c) { }
c. public int setVar(int a, float c, int b) {return a;}
d. public int setVar(int a, int b, float c) {return a;}
e. protected float setVar(int a, int b, float c) {return c;}

86.)
Given:

11. public static void main (String[] args) {
12. Integer a = new Integer(10);
13. Integer b = new Integer(10);
14. Integer c = a;
15. int d = 10;
16. double e = 10.0;
17. }

Which three evaluate to true? (Choose three.)

a. (a == c)
b. (d == e)
c. (b == d)
d. (a == b)
e. (b == c)
f. (d == 10.0)
87.)
Which two statements are true regarding the return values of properly written hashCode and equals methods returned from two instances of the same class? (Choose two.)

a. If the hashCode values are different, the objects might be equal.
b. If the hashCode values are the same, the objects must be equal.
c. If the hashCode values are the same, the objects might be equal.
d. If the hashCode values are different, the objects must be unequal.
88.)
Given:

1. abstract class AbstractIt {
2. abstract float getFloat();
3. }
4. public class AbstractTest extends AbstractIt {
5. private float f1 = 1.0f;
6. private float getFloat() { return f1; }
7. }

What is the result?

a. Compilation succeeds.
b. An exception is thrown.
c. Compilation fails because of an error at line 2.
d. Compilation fails because of an error at line 6.
89.)
Which three statements are true? (Choose three.)

a. Assertion checking is typically enabled when a program is deployed.
b. It is never appropriate to write code to handle failure of an assert statement.
c. Assertion checking is typically enabled during program development and testing.
d. Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a
per-class basis.
e. Assertion checking can be selectively enabled or disabled on both a per-package basis
and a per-class basis.
90.)
Click the Exhibit button.

What is the result?

1. public class X {
2. public static void main (String [] args) {
3. try {
4. badMethod();
5. System.out.print(“A”);
6. }
7. catch (Exception ex) {
8. System.out.print(“B”);
9. }
10. finally {
11. System.out.print(“C”);
12. }
13. System.out.print(“D”);
14. }
15. public static void badMethod() {
16. throw new Error();
17. }
18. }

a. ABCD
b. Compilation fails.
c. C is printed before exiting with an error message.
d. BC is printed before exiting with an error message.
e. BCD is printed before exiting with an error message.