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/random741f May 20 '20 edited May 20 '20
The parameter is a memory address. It's the memory address that needs to be by value. Yes no part of the parameter is changeable. You can't change the memory address. :D
https://www.educative.io/edpresso/pass-by-value-vs-pass-by-reference
Clearly every single person on StackOverflow is wrong and you are just right. :)
https://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value
https://stackoverflow.com/questions/7893492/is-java-really-passing-objects-by-value
https://stackoverflow.com/questions/9109529/pass-by-value-and-pass-by-reference-in-java
https://stackoverflow.com/questions/12757841/are-arrays-passed-by-value-or-passed-by-reference-in-java
https://stackoverflow.com/questions/24101960/why-is-java-pass-by-value-only
Go ahead and argue with everyone on StackOverflow. Yep you're an amateur not even working in the industry. :)
You know what they say, "If everyone you meet is an asshole, you're the problem."
I do not actually believe you are trolling. I do think you have very different definitions of pass by reference than everyone else in the world.