What is the result?


What is the result?
A. 10 Hello Hello 11
B. 10 Hello Hello 121
C. 100 Hello 121
D. 100 Hello Hello 121
E. 10 Hello 11

Download Printable PDF. VALID exam to help you PASS.

8 thoughts on “What is the result?

  1. For Integer and primitive int you’re passing copies of these values. Which doesn’t change the actual values.
    For StringBuilder, you’re passing the actual object reference and not just a copy, so the value is actually changed

  2. Answer A:

    When we have passed the StringBuilder object reference “sb” to the doString() method, we have actually passed the VALUE of that reference variable, and assign it to the local variable “s”. Now at this point, both “sb” and “s” are pointing to the same StringBuilder object which includes the string “Hello”. Therefore, the changes applied to the variable “s” are actually made to the original string builder object, because “s” is pointing to that original string builder object. As a result, both “s” and “sb” are going to be ” Hello Hello”.


Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.