JAVA DUMPS 5(SCJP)

QUESTION NO: 23


Which statement is true about assertion in the Java programming language?

A. Assertion expressions should not contain side effects.

B. Assertion expression values can be any primitive type.

C. Assertion should be used for enforcing preconditions on public methods.

D. An AssertionError thrown as a result of a failed assertion should always be handled by

the enclosing method.


Answer: A


QUESTION NO: 24


Given:

1. package foo;

2.

3. import java.util.Vector;

4.

5. private class MyVector extends Vector {

6. int i = 1;

7. public MyVector() {

8. i = 2,

9. }

10. }

11.

12. public class MyNewVector extends MyVector {

13. public MyNewVector() {

14. i = 4;

15. }

16. public static void main(String args[]) {

17. MyVector v = new MyNewVector();

18. }

19. }


What is the result?

A. Compilation succeeds.

B. Compilation fails because of an error at line 5.

C. Compilation fails because of an error at line 6.

D. Compilation fails because of an error at line 14.

E. Compilation fails because of an error at line 17.


Answer: B


QUESTION NO: 25


Given:

1. class TestSuper {

2. TestSuper(int i) { }

3. }

4. class TestSub extends TestSuper{ }

5. class TestAll {

6. public static void main (String [] args) {

7. new TestSub();

8. }

9. }


Which is true?

A. Compilation fails.

B. The code runs without exception.

C. An exception is thrown at line 7.

D. An exception is thrown at line 2.


Answer: A


QUESTION NO: 26


Given:

10. int i = 0;

11. for (; i <4; i += 2) {

12. System.out.print(i + "");

13. }

14. System.out.println(i);


What is the result?

A. 0 2 4

B. 0 2 4 5

C. 0 1 2 3 4

D. Compilation fails.

E. An exception is thrown at runtime.


Answer: A


QUESTION NO: 27


Given:

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. }


What is the result?

A. value = 3

B. value = 4

C. value = 5

D. value = 6

E. value = 7

F. value = 8


Answer: F


QUESTION NO: 28


Which three form part of correct array declarations? (Choose three)

A. public int a []

B. static int [] a

C. public [] int a

D. private int a [3]

E. private int [3] a []

F. public final int [] a


Answer: A, B, F

2 comments:

Anonymous said...

will u plz provide the Explaination for the answer. it will help us
Swapnil P.

Anonymous said...

pls provide explanation for answers it would be a great help.

Post a Comment