M
M
Michael2018-04-05 15:36:21
Java
Michael, 2018-04-05 15:36:21

Does Java have the equivalent of a C++ reference in methods?

In C++, you can write it like this:

void func (int& a, int& b)
{
      //do smth
}

If the variables passed to func change their values ​​inside it, they will be saved after exiting it. Is it
possible to do the same in Java or not?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2018-04-05
@xez

www.quizful.net/interview/java/passing-parameters-...

Passing by reference means passing a reference to an object. In this case, the method implementation could potentially modify the passed object (for example, by calling a method that changes the state of the object).
In the case of passing by value, the parameter is copied. The parameter change will not be noticeable to the caller.
In Java, objects are always passed by reference, and primitives are always passed by value
. Pass By Reference means the passing the address itself rather than passing the value. Pass By Value means passing a copy of the value to be passed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question