Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Is Java “pass-by-reference” or “pass-by-value”?

I thought Java uses pass-by-reference.

However, I've seen a couple of articles that claim that it isn't (the blog post says that Java uses pass-by-value).

I don't think I understand the difference between them.

What is the explanation?

2 Answers

Pass by reference is a method of passing parameters to the function which we can find in C and C++ programming languages. As java does not support the pointers explicitly we can consider that java uses Pass-by-value method to pass parameters to the function.
In Pass-by-value method of parameter passing we pass the actual value of the parameters where as In Pass-by-Reference method of parameter passing we pass the address of the variable which needs to be passed...
Java is strictly pass by value. This is because in java the method parameter values are copied to another variable and then the copied object is passed.

Login / Signup to Answer the Question.