File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Pass by val/ref ? 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 "Pass by val/ref ?" Watch "Pass by val/ref ?" New topic

Pass by val/ref ?

Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66
class ValHold{
public int i = 10;
public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
public void amethod(){
int i = 99;
ValHold v = new ValHold();
}//End of amethod
public void another(ValHold v, int i){
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.println(v.i+ " "+i);
}//End of another
The code above executes to give the following answers - 10,0,20. 10 and 0 are understandable but why 20. Could somebody please clarify!
Ajay Kumar
Ranch Hand

Joined: Apr 28, 2000
Posts: 87
Please refer to the following link for explanation.
Ajay K
[This message has been edited by Ajay Kumar (edited July 06, 2000).]

Regds<BR>Ajay Kumar
Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66
Thanks Ajay!!
I agree. Here's the link:
subject: Pass by val/ref ?
It's not a secret anymore!