Member-only story
Featured
Is Java PASS-BY-REFERENCE?
Primitives → Passed by value (copy of the value). Objects → Passed by value (copy of the reference)
What is Pass-by-Reference?
- You send a reference (memory address) to the method.
- If the method changes the value, it modifies the original variable.
c++ code
#include <iostream>
using namespace std;
void modifyNumber(int &x) { // x is passed by reference.
x = 10; // Changes original value
}
int main() {
int a = 5;
modifyNumber(a);
cout << a << endl; // Output: 10
return 0;
}
What is Pass-by-Value?
- Pass-by-value means Java sends a copy of the value to a method.
- If you change the value inside the method, the original value doesn’t change.
python code
x =5
def modifyNumber(x):
x = 10
modifyNumber(x)
print(x) # x = 5
Non Medium Member Alert!!!
If you block by medium pay wall, You can read it with this link.
Dear Folks, Your 50 claps 👏👏 help the discussion [article] reach more developers 👀 on Medium, and your comments 💬 make me to keep writing. If you found this article helpful, consider supporting my writing with a…