• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can someone explain!!!

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

Edited By Corey McGlone: Added CODE Tags
[ July 24, 2003: Message edited by: Corey McGlone ]
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

First off we I'm assuming you understand the order of the "System.out"s, if not just let us know.
So now we have:
1)at line 23 we create a new ValHold object vh which has vh.i=10
at line 24 we use our new ValHold object vh created at line 23 and set v=vh
so now v.i=10
2)in method another() i was passed in with value of 99
but we immediately set i=0 at line 21
3)at line 16 we pass v into method another() and v.i=30 at this point
when we pass objects as parameters we are actually passing a copy of the reference
so at line 22 when v.i=20 that will also apply to the v object in the method amethod()
at line 24 we set method anonther()'s v to point to a diferent object, this does does not affect method amethod()'s v though
so at line 17 v.i=20
Hope that makes sense.
 
Salman Riaz
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cheers paul!!
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also check out this.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic