File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Pass by val/ref ?" Watch "Pass by val/ref ?" New topic
Author

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();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);
}//End of amethod
public void another(ValHold v, int i){
i=0;
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
Ankur,
Please refer to the following link for explanation.
http://www.javaranch.com/ubb/Forum24/HTML/001293.html
regds
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!!
 
 
subject: Pass by val/ref ?