I am having difficulty understanding How parameters are passed in java.
heres my code:
so i am passing the address of Hippo h2 to copyHippo through method copy. So when i modify the value of size of copyHippo in the copy method, it gets reflected in the main method, which can be seen by the output of the sop.
I just cant understand why the string variables value is not getting modified. Because isnt it completely similar to the copyHippo reference variable?
but why is the value of s2(null here)passed instead of the address.
I mean copyHippo is a reference variable which points to the same object to which h2 and h1 created in the main method are pointing to.so when i modify the value of instance variables of copyHippo in the copy function, the values of instance variables in the main function gets modified.
Same should be the case for the string variable too right? But what am i missing here?