r/javahelp • u/djpfg • May 15 '20
how reference variables are passed as method arguments in Java
Hello, I am struggling to understand what this question is asking for, I know in C++ for pass by reference the address of the variable is passed and altered before returning unlike pass-by value(correct me if Im wrong) but in java I thought all values were automatically pass by reference? struggling to make sense of the question so any help at all will be greatly appreciated:)
Explain the difference between how pass-by-reference operates in C++ and how reference variables are passed as method arguments in Java. A good answer will include a simple example of each
16
Upvotes
1
u/Jarl-67 May 18 '20
It isn’t pass by value because you say so. Logic says otherwise. The parameter is an object, and it’s the entire object that needs to be by value. The only reason you think it’s by value is that that the actual reference (key word) is not changeable. When a parameter is by value, no part of the parameter is changeable.
Didn’t you learn this in college? I assume you have a degree but maybe that’s too big of an assumption.
This isn’t a belief by the way, you are the one who believes. That’s why you can’t actually argue the point but instead just restate your untenable position.