Forums Register Login

Stack

+Pie Number of slices to send: Send

The output of above code is:
st1 has: []
st2 has: [100]
I thought the output would be:
st1 has: [100]
st2 has: [100]


Plz some one explain me why the above code gives such output??
regds
Arpana
+Pie Number of slices to send: Send
Inside method, the parameters st1 and st2 are not the same as the local variables st1 and st2 in the main method. Think of them as st1' and st2' . After the invokation they point to the same Stack objects as the local variables in main do. Therefore, modifying the content of st2' will also be reflected in the variable st2 in the main method. However st1'= st2' will not set st1 to st2' , because st1 and st1' are different variables. st1' dissapears after the method invokation returns, but st1 remains unchanged.
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 693 times.
Similar Threads
Stack referencing other stack
Doubt in StirngBuffer
How about with java.util.Stack??
Static Block
Stack referencing stack
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:41:19.