This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

JQ+ Qs.....  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Could someone please explain, why the answer is [100][] ? I think it should be[100][100] as the parameters for the methods are Object.
Thanks,
Arun
 
Gold Digger
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even objects are passed by value. In this case, the reference (not the whole stack object) s1 and s2 are copied and passed to the method processStacks. Inside the method, if you change the reference (x2=x1) then the change is not reported outside the method because the reference were copied... That is, outside the method, s1 and s2 will still refer to their initial stack.
(Imagine the nightmare it would be to find a bug if reference passing was allowed in Java. I find it much more better that way, but it's a matter of personal taste, of course.)
HIH
 
Arun Mishra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Valentin,
Could you please explain me how we can differentiate whether the parameter is whole object or reference ?
Arun
 
Valentin Crettaz
Gold Digger
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"whole" objects are never passed as parameters only (a copy of) the reference to the object is passed.
There is an interesting document about that: Javaranch: pass-by-Value Please
HIH
[ January 22, 2002: Message edited by: Valentin Crettaz ]
 
Arun Mishra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Valentin
 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
need some qustions or code to practice this. can you send me some links or resources ?

Originally posted by Valentin Crettaz:
"whole" objects are never passed as parameters only (a copy of) the reference to the object is passed.
There is an interesting document about that: Javaranch :-P ass-by-Value Please
HIH

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!