JAVA DUMPS 3(SCJP)

QUESTION NO: 10


 

You want a class to have access to members of another class in the same package. Which

is the most restrictive access that accomplishes this objective?


 

A. public

B. private

C. protected

D. transient

E. default access


 

Answer: E


 

QUESTION NO: 11


 

Given:

11. int x = 3;

12. int y = 1;

13. if (x = y) {

14. System.out.println("x = " + x);

15. }


 

What is the result?

A. x = 1

B. x = 3

C. Compilation fails.

D. The code runs with no output.

E. An exception is thrown at runtime.


 

Answer: C


 

QUESTION NO: 12


 

Given:

1. public class Test {

2. public static void aMethod() throws Exception {

3. try {

4. throw new Exception();

5. } finally {

6. System.out.println("finally");

7. }

8. }

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

10. try {

11. aMethod();

12. } catch (Exception e) {

13. System.out.println("exception");

14. }

15. System.out.println("finished");

16. }

17. }


 

What is the result?


 

A. finally

B. exception

finished

C. finally

exception

finished

D. Compilation fails.


 

Answer: C


 

QUESTION NO: 13


 

Given:

1. public interface Foo {

2. int k = 4;

3. }


 

Which three are equivalent to line 2? (Choose three)

A. final int k = 4;

B. public int k = 4;

C. static int k = 4;

D. abstract int k = 4;

E. volatile int k = 4;

F. protected int k = 4;


 

Answer: A, B, C


 

QUESTION NO: 14


 

Given:

1. package test1;

2. public class Test1 {

3. static int x = 42;

4. }

1. package test2;

2. public class Test2 extends test1.Test1 {

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

4. System.out.println("x = " + x);

5. }

6. }


 

What is the result?

A. x = 0

B. x = 42

C. Compilation fails because of an error in line 2 of class Test2.

D. Compilation fails because of an error in line 3 of class Test1.

E. Compilation fails because of an error in line 4 of class Test2.


 

Answer: D


 

QUESTION NO: 15


 

Given:

1. class A {

2. protected int method1(int a, int b) { return 0; }

3. }


 

Which two are valid in a class that extends class A? (Choose two)

A. public int method1(int a, int b) { return 0; }

B. private int method1(int a, int b) { return 0; }

C. private int method1(int a, long b) { return 0; }

D. public short method1(int a, int b) { return 0: }

E. static protected int method1(int a, int b) { return 0; }


 

Answer: A, C

3 comments:

Anonymous said...

Q14: the correct answer should be E I believe.

Anonymous said...

Answer E is correct for Question no 14.

Anonymous said...

IN Q14: If you change the access modifier in the x var declaration to public you dont have any problem with the code.I thik that this question is focused on access modifiers so Answer D is correct i belive.

Post a Comment