JAVA DUMPS 10(SCJP)

QUESTION NO: 49

Given:

10. public Object m() {

11. Object o = new Float(3.14F);

12. Object [] oa = new Object[1];

13. oa[0] = o;

14. o = null;

15. oa[0] = null;

16. return 0;

17. }

When is the Float object, created in line 11, eligible for garbage collection?

A. Just after line 13.

B. Just after line 14.

C. Just after line 15.

D. Just after line 16 (that is, as the method returns).

Answer: B


 

QUESTION NO: 50

Given:

11. public void test(int x) {

12. int odd = x%2;

13. if (odd) {

14. System.out.println("odd);

15. } else {

16. System.out.println("even");

17. }

18. }

Which statement is true?

A. Compilation fails.

B. "odd" will always be output.

C. "even" will always be output.

D. "odd" will be output for odd values of x, and "even" for even values.

E. "even" will be output for add values of x, and "odd" for even values.

Answer: A


 

QUESTION NO: 51

Which two create an instance of an array? (Choose two)

A. int[] ia = new int[15];

B. float fa = new float[20];

C. char[] ca = "Some String";

D. Object oa = new float[20];

E. int ia[][] = { 4, 5, 6, }, { 1, 2, 3 };

Answer: A, D


 

QUESTION NO: 52

Given:

1. class Super {

2. public int getLenght() { return 4; }

3. }

4.

5. public class Sub extends Super {

6. public long getLenght() { return 5; }

7.

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

9. Super sooper = new Super();

10. Sub sub = new Sub();

11. System.out.println(

12. sooper.getLenght() + "," + sub.getLenght() );

13. }

14. }

What is the output?

A. 4,4

B. 4,5

C. 5,4

D. 5,5

E. Compilation fails.

Answer: E


 

QUESTION NO: 53

Given:

1. public class Test {

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

3. int x = 0;

4. assert (x > 0): "assertion failed";

5. System.out.printIn("finished");

6. }

7. }

What is the result?

A. finished

B. Compilation fails.

C. An AssertionError is thrown.

D. An AssertionError is thrown and finished is output.

Answer: A

1 comments:

Anonymous said...

Question 53: Answer is C. If you are compiling and running the code, by default you will get the result "finished". Compile the code using compiler option "-source 1.4" and when you run it, use the runtime option "-ea" or "-enableassertions. That way you'll be enabling the assertion, which is disabled by default.

Post a Comment