Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Hard

Question 49

What will be the result of compiling and executing Test class?

  • A

    Good

  • B

    Good_Morning

  • C

    None of the other options

  • D

    _Morning

Reveal correct answer

Correct answer: B

Explanation

When change method is called, both variable s and sb refers to same StringBuilder object.

Line 9 modifies the passed object and appends "_Morning" to it. As a result s now refers to "Good_Morning" and sb also refers to "Good_Morning" so when control goes back to calling method main(String[]) Line 5 prints "Good_Morning" on to the console.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need