• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Stack

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic