Create a class human
Public classHuman {Private intAge ; Private intSex//0-Female, 1-male Public intGetage () {returnAge ; } Public voidSetage (intAge ) { This. Age =Age ; } Public intGetsex () {returnsex; } Public voidSetsex (intsex) { This. Sex =sex; }}
Test class
classhumantest {@TestvoidTest () {Human Human=NewHuman (); intAge=Human.getage (); Addage (age); System.out.println (age); Man (human); System.out.println (Human.getage ()); assertHuman.getsex () ==1; } voidMan (Human Human) {human.setage (20); Human.setsex (1); } voidAddage (intAge ) { Age+=2; }}
Output results
020
(1). Value passing: a copy of the value is passed. That means they don't close each other after they're delivered.
the difference between heap and stack:
(1). Stack: The stack holds the base data type (basic data types include: int, short, double, long, float, Boolean, char, Byte, Note no string), and a reference to the object.
(2). Heap: heap memory is used to hold objects and arrays created by new. The memory allocated in the heap is managed by the automatic garbage collector of the Java Virtual machine.
When passing a parameter as an object, a reference to the object is passed in the stack, and the object's properties exist in the heap, the property value is modified, the reference to the object is unchanged,
So the essence is still the value of transmission;
"There is only value passing in the Java language, no reference passing" understanding