Why java is passed by value and not only passed by reference

Value is passed: when the method is called when passing a variable, the value of the variable pass into. For example a = 4, a time of the incoming, 4 is passed. At this time, the value of variable a is 4, the address is stored at the address 4

Transmitting reference: pass in the address of a variable, the address of the incoming value of 4.

When the parameter is a process variable is an object variable, e.g., Student s = new Student () ; s passing the method, when the value of s is actually the address of student instance of an object , the value of s is passed, i.e., address of the instance of the object, rather than s address, i.e. the address of the instance of the object storage address .

So java is only passed by value.

Guess you like

Origin www.cnblogs.com/cai-cai777/p/11896630.html