JAVA DUMPS 14 (SCJP)

QUESTION NO: 72

You want subclasses in any package to have access to members of a superclass. Which is

the most restrictive access that accomplishes this objective?

A. public

B. private

C. protected

D. transient

E. default access

Answer: C


 

QUESTION NO: 73

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.

Answer: A


 

QUESTION NO: 74

Given:

20. public float getSalary(Employee e) {

21. assert validEmployee(e);

22. float sal = lookupSalary(e);

23. assert (sal>0);

24. return sal;

25. }

26. private int getAge(Employee e) {

27. assert validEmployee(e);

28. int age = lookupAge(e);

29. assert (age>0);

30. return age;

31. }

Which line is a violation of appropriate use of the assertion mechanism?

A. line 21

B. line 23

C. line 27

D. line 29

Answer: A


 

QUESTION NO: 75

Given:

1. public class A {

2. void A() {

3. System.out.println("Class A");

4. }

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

6. new A();

7. }

8. }

What is the result?

A. Class A

B. Compilation fails.

C. An exception is thrown at line 2.

D. An exception is thrown at line 6.

E. The code executes with no output.

Answer: E


 

QUESTION NO: 76

Given:

1. class Bar { }

1. class Test {

2. Bar doBar() {

3. Bar b = new Bar();

4. return b;

5. }

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

7. Test t = new Test();

8. Bar newBar = t.doBar();

9. System.out.println("newBar");

10. newBar = new Bar();

11. System.out.println("finishing");

12. }

13. }

At what point is the Bar object, created on line 3, eligible for garbage collection?

A. After line 8.

B. After line 10.

C. After line 4, when doBar() completes.

D. After line 11, when main() completes.

Answer: C


 

QUESTION NO: 77

Given:

1. interface Beta {}

2.

3. class Alpha implements Beta {

4. String testIt() {

5. return "Tested";

6. }

7. }

8.

9. public class Main1 {

10. static Beta getIt() {

11. return new Alpha();

12. }

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

14. Beta b = getIt();

15. System.out.println( b.testIt() );

16. }

17. }

What is the result?

A. Tested

B. Compilation fails.

C. The code runs with no output.

Answer: B

0 comments:

Post a Comment