Object can be passed as a parameter to a method
Instead of passing the value of the object itself to the parameter, the passed object passes the reference value of the object to the parameter
void method1 (num num) {
num.i+=10;
}
Any changes in the contents of the Method1 method in vivo are also changes to the object itself
void method2 (num num) {
Num=new Num ();
num.i=100;
}
The object content here hasn't changed.
Because an object in Java is passed as a parameter, it is equivalent to copying a copy of the object's in-memory address to a parameter
Method1, because the formal parameter and the object have the same memory address, so the modification of the formal parameter, the natural object itself content also changed.
And in Method2, just as in Method 1, they still point to the same memory address, but new Num (), which opens up a new area of memory
This causes the shape to participate in the object storage address is not the same, natural changes in the parameters will not be reflected on the object.
This
Represents a reference to the current object
1. Return the current object, or pass the current object as a parameter to another method
Classname method () {
return this;}
2. If the local variable has the same name as the attribute member variable of the owning class (when the property is encapsulated)
This.name=name;
3. Another constructor method that calls its owning class in a constructor method
However, it can be called only once and before any statements in the method body
Final
A final defined object can only point to a unique object , and it cannot be pointed to another object
But the value of an object itself can be changed, except that the object reference (point) is immutable.
Java Basic Knowledge _ object