r/javahelp • • 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

30 comments sorted by

View all comments

1

u/wildjokers May 15 '20

Java is pass-by-value and only pass-by-value.

http://www.javadude.com/articles/passbyvalue.htm

-1

u/Jarl-67 May 16 '20

Except if you pass an object as a parameter....

1

u/wildjokers May 16 '20

I will reiterate, java is pass-by-value and only pass-by-value. Did you read the article I linked to?