Object Reference, Compiler
1 public class Test {2 public static void main (String [] args) {3 Human aPerson = new Human (122 ); 4} 5 6} 7 class Human {8/* constructor */9 public Human (int h) {10 this. height = h; 11} 12/* accessor */13 public int GetHeight () {14 return this. height; 15} 16/* mutator */17 public void GrowHeight (int h) {18 this. height + = h; 19} 20 private int height; 21} View Code
APerson indicates that the reference object is stored in the memory stack.
But !!!
In Java, all (common) objects are stored on the stack. Therefore, the full meaning of the new Keyword is to create an object on the stack.
Objects of the basic type (primitive type), such as int and double, are stored on the stack. New is not required when we declare the basic type. Once declared, Java will directly store basic types of data on the stack. Therefore, the variable name of the basic type indicates the data itself, not the reference.
Reference Value assignment:
When we assign a reference value to another reference, we actually copy the object address. The two references point to the same object. For example, dummyPerson = aPerson; will cause: