class Ideone
{
int x;
public static void main (String[] args) throws java.lang.Exception
{
Ideone i;
i = new Ideone();
i.x = 25;
System.out.println(i.x);
f(i);
System.out.println(i.x);
g(i);
System.out.println(i.x);
}
public static void f(Ideone j){
j = new Ideone();
j.x = 55; // It just changes new instance of J. It is not changing actual object
}
public static void j(Ideone j){
j.x = 52; // It modifies actual object
}
}
I have a doubt in this. In case of j function, it modifies actual object. Is it not pass by reference? We are passing the object and modifying it inside j.
But I am doing the samein function f also. Passing the object and modifying it. But it is not modifying the original object.
I am confused the behaviour between these.
As per the highly voted answer, I am passing an URL in both cases. And I am modifying the content in the URL. But it is visible to all in one case but it is not in the other case.