Given:
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
Given:
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
10 Hello Hello 11
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
A:
# javac Test16.java
# java Test16
10 Hello Hello 11
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”.
A
The correct answer is A
A
E