aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Stack Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Stack" Watch "Stack" New topic
Author

Stack

Arpana Rai
Ranch Hand

Joined: Nov 12, 2002
Posts: 93

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


SCJP1.4(91%)
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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.


SCJP2. Please Indent your code using UBB Code
 
 
subject: Stack