aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JQ+  Qs..... 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 "JQ+  Qs....." Watch "JQ+  Qs....." New topic
Author

JQ+ Qs.....

Arun Mishra
Greenhorn

Joined: Jan 02, 2002
Posts: 16
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
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Arun Mishra
Greenhorn

Joined: Jan 02, 2002
Posts: 16
Thanks Valentin,
Could you please explain me how we can differentiate whether the parameter is whole object or reference ?
Arun
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
"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

Joined: Jan 02, 2002
Posts: 16
Thanks Valentin
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
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
 
jQuery in Action, 2nd edition
 
subject: JQ+ Qs.....