Chapter ONE
Utilizing Java Object-Oriented Approach - Part 1


Exam Objectives

Declare and instantiate Java objects including nested class objects, and explain the object life-cycle including creation, reassigning references, and garbage collection.
Create classes and records, and define and use instance and static fields and methods, constructors, and instance and static initializers.
Implement overloading, including var-arg methods.

Answers

1. The correct answer is B.

Explanation:

2. The correct answers are C and D.

Explanation:

3. The correct answers are A and E.

Explanation:

4. The correct answers are B and D.

Explanation:

5. The correct answers are A, B, and C.

Explanation:

6. The correct answer is D:

Explanation:

7. The correct answers are A, C, and D.

Explanation:

8. The correct answers are A, C, and D.

Explanation:

9. The correct answer is B.

Explanation:

10. The correct answers are A and B.

Explanation:

In Java, a method signature consists of the method name and the parameter list. The return type, access modifier, and exception list are not considered part of the method signature.

11. The correct answers are C and D.

Explanation:

12. The correct answer is B.

Explanation:

Java is strictly pass-by-value. This means that when passing a variable to a method, Java passes a copy of the variable’s value, not the variable itself. Changes to the parameter inside the method do not affect the original variable.

13. The correct answer is B.

Explanation:

14. The correct answers are B and D.

Explanation:

15. The correct answer is A.

Explanation:

16. The correct answer are A and D.

Explanation:

17. The correct answer is A.

Explanation:

18. The correct answer is B.

Explanation:

In Java, the order of initialization when a class is loaded and an instance of that class is created is as follows:

  1. Static fields and static initializers are processed in the order they appear in the class definition. First, the static initializer block prints "1. Static initializer". Then, the static field staticValue is initialized by calling initializeStaticValue(), which prints "2. Static value initializer".

  2. Instance fields and instance initializers are processed in the order they appear when an instance of the class is created. First, the instance field instanceValue is initialized by calling initializeInstanceValue(), which prints "3. Instance value initializer". Then, the instance initializer block prints "3. Instance initializer".

  3. Constructors are executed after all fields and instance initializers have been processed. The constructor in this case prints "4. Constructor".

The numbering of the output for "3. Instance initializer" and "3. Instance value initializer" in the question might seem to suggest they are executed simultaneously or out of order, but it’s important to remember that instance fields and instance initializers execute in the order they appear in the class, before the constructor is executed. The duplicate numbering means that instance field initializers run first, followed by instance initializers, and finally, the constructor runs.

19. The correct answers are A and C.

Explanation:

20. The correct answer is B.

Explanation:

21. The correct answer is A.

Explanation:

22. The correct answers are A and D.

Explanation:

23. The correct answer is A.

Explanation:

24. The correct answer is C.

Explanation:

Do you like what you read? Would you consider?


Do you have a problem or something to say?

Report an issue with the book

Contact me