SCJP - Page -8

71.)
Click the Exhibit button.
What is the result?

1. class ThreadTest extends Thread {
2. int n ;
3. public ThreadTest (int n) { this.n = n; }
4. public void run() {
5. for (int i=0; i<3; i++)
6. System.out.print(“T”+n+” “);
7. }
8. public static void main (String[] args) {
9. Thread t1 = new ThreadTest (1);
10. Thread t2 = new ThreadTest (2);
11. t1.setPriority (Thread.MAX_PRIORITY);
12. t2.setPriority (Threead.MIN_PRIORITY);
13. t1.start();
14. t2.start();
16. }
17. }

a. T1T2T1T2T1T2T1T2
b. T1T1T1T1T2T2T2T2
c. T2T2T2T2T1T1T1T1
d. Deadlock; there is no output.
e. The behavior is not specified by the Java Language Specification.
72.)
Given:

1. class BaseClass {
2. private float x = 1.0f;
3. protected void setVar(float f) { x = f; }
4. }
5. class Subclass extends BaseClass {
6. private float x = 2.0f;
7. // insert code here
8. }

Which two are valid example of method overriding when inserted at line 7? (Choose two.)

a. void setVar(float f) { x = f; }
b. public void setVar(int f) { x = f; }
c. public void setVar(float f) { x = f; }
d. public double setVar(float f) { return f; }
e. public final void setVar(float f) { x = f; }
f. protected float setVar() { x = 3.0f; return 3.0f; }
73.)
Click the Exhibit button.

What is the result?

1. public class SwitchTest {
2. public static void main (String [] args) {
3. System.out.println(“value = “ + switchIt (4) );
4. }
5. public static int switchIt (int x) {
6. int j = 1;
7. switch (x) {
8. case 1: j++;
9. case 2: j++;
10. case 3: j++;
11. case 4: j++;
12. case 5: j++;
13. default : j++;
14. }
15. return j + x ;
16. }
17. }

a. value = 3
b. value = 4
c. value = 5
d. value = 6;
e. value = 7;
f. value = 8;
74.)
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.
75.)
Given:

1. public sbstract class Test {
2. public abstract void methodA();
3.
4. public abstract void methodB()
5. {
6. System.out.println(“Hello”);
7. }
8. }

Which two changes, independently applied, allow this code to compile? (Choose two.)

a. add a method body to methodA
b. replace lines 5 – 7 with a semicolon (“;”)
c. remove the abstract qualifier from the declaration of Test
d. remove the abstract qualifier from the declaration of methodA
e. remove the abstract qualifier from the declaration of methodB
76.)
Given:

1. class Exc0 extends Exception { }
2. class Exc1 extends Exc0 { }
3. public class Test {
4. public static void main (String args[]) {
5. try {
6. throw new Exc1();
7. } catch (Exc0 e0) {
8. system.out.println(“Ex0 caught”);
9. }catch (Exception e) {
10. System.out.println(“Exception caught”);
11. }
12. }
13. }

What is the result?

a. Ex0 caught
b. exception caught
c. Compilation fails because of an error at line 2.
d. Compilation fails because of an error at line 6.
77.)
Click the Exhibit button.

What is the result?

1. class A {
2. int x;
3.
4. boolean check() {
5. x++;
6. return true;
7. }
8.
9. voiid zzz() {
10. x=0;
11. if ((check() | check()) || check()) {
12. x++;
13. }
14. System.out.println(“x = “ + x);
15. }
16.
17. public static void main(String[] args){
18. (new A()).zzz();
19. }
20. }

a. x = 0
b. x = 1
c. x = 2
d. x = 3
e. x = 4
f. Compilation fails.
78.)
What allows the programmer to destroy an object x?

a. x.delete()
b. x.finalize()
c. Runtime.getRuntime().gc()
d. explicitly setting the object's reference to null
e. ensuring there are no references to the object
f. Only the garbase collection system can destroy an object.
79.)
Given:

11. for (int i=0; i<3; i++) {
12. switch(i) {
13. case 0: break;
14. case 1: System.out.print(“one”);
15. case 2: System.out.print(“two”);
16. case 3: System.out.print(“three”);
17. }
18. }
19. System.out.println(“done”);

What is the result?

a. done
b. one two done
c. Compilation fails.
d. one two three done
e. one two three two three done
80.)
Given:

1. public class X {
2. public X aMethod() { return this; }
3. }

1. public class Y extends X {
2.
3. }

Which two methods can be added to the definition of class Y? (Choose two.)

a. public void aMethod() {}
b. private void aMethod() {}
c. public void aMethod(String s) {}
d. private Y aMethod() { return null; }
e. public X aMethod() { return new Y(); }