0

Possible Duplicate:
Is Java “pass-by-reference”?
Pass by value or Pass by reference in Java?

When we pass the arguments to a method inside a java class. Are the parameters passed in By VALUE or BY REFERENCE as default?

There can be two possibilities,
1. if we pass arguments to a method from another method within the same class.
2. if we pass arguments to a method from another class.

Secondly, if i want to pass values by reference (in case default attribute of java is By Value) then what should i do?

Community
  • 1
  • 1
adeel iqbal
  • 494
  • 5
  • 23

2 Answers2

5

Whatever be the case.. Java is PASS BY VALUE and even references are passed by value

and to get more examples here are few interesting links to read out

http://www.javaworld.com/javaqa/2000-05/03-qa-0526-pass.html
How to do the equivalent of pass by reference for primitives in Java
Pass by value or Pass by reference in Java?

Community
  • 1
  • 1
exexzian
  • 7,782
  • 6
  • 41
  • 52
0

I am pretty sure that Java is all pass by value. C/C++ is in to passing by reference. As far as working around passing by reference it is quite easy. As with with C, Java has return type methods. You simply place the variable to the left of the assignment ( = ) operator to call of a method that returns what its new value should be. Plus a few other ways.

String name = "Jon Doe";

name = getName();

String getName() {

//code to get name goes here.

}