J
JustSomeGuy
I'm a C++ programmer moving towards writing some java applications.
I'm quite familiar with Java, but I'm a little muddled over passing by
value,
vs passing by refrence.
In C++:
int & function(int x, int &y)
the function may modify x but the changes will not effect the callers value
of x.
the function may modify y and the changes will effect the callers value of
y.
the return is a refrence to an integer within the function and a copy of it
is
made in the callers scope.
As I understand it everything in Java is a reffrence. So how does this work?
If everything is a refrence then what is the point of having parameters, why
not
just use global variables?
I'm quite familiar with Java, but I'm a little muddled over passing by
value,
vs passing by refrence.
In C++:
int & function(int x, int &y)
the function may modify x but the changes will not effect the callers value
of x.
the function may modify y and the changes will effect the callers value of
y.
the return is a refrence to an integer within the function and a copy of it
is
made in the callers scope.
As I understand it everything in Java is a reffrence. So how does this work?
If everything is a refrence then what is the point of having parameters, why
not
just use global variables?