is java pass by reference or value
explain pass by value and reference
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Thomas
15 January, 22:56
JLS
When the method ... is invoked ..., the values of the actual argument expressions initialize newly created parameter variables
Means: always by value. It may be confusing, but if you try to pass a reference, then this is just a regular variable and a copy is passed. You can try this, If you pass a reference to a method and inside the method you assign a new object to your reference var (change the reference itself, not the object behind it). You'll see that nothing will change in main. It still references the same old object it referenced before invoking the method.
0