Object as Reference not working
Code :
public class GG{
public static void main(String[] args) {
Integer i = new Integer(10);
System.out.println("Before Call:"+i);
change(i);
System.out.println("After Call:"+i);
}
public static void change(Integer x){
x=20;
}
}
Here the output is coming
Before Call:10
After Call:10
I am confused when i am passing an object in a function then why the value is not changed as objects are passed by reference??
Re: Object as Reference not working
Re: Object as Reference not working
HI..Can u please tell me the link from where i can see a solution on oracle forums
Thnks
Re: Object as Reference not working
The link is right there in my previous response. Or log in to the Oracle forums and view your profile, where you will find a list of your posts.
db
Re: Object as Reference not working
Dont know if this has been answered or not, but you are using local variables, and expecting a global change. You have to either make i global, or change within the main method