From the previous study, we already know that variables declared by a class are called objects. Objects, which are variables, are responsible for storing references to ensure that the object can operate the variables assigned to the object and call methods in the class. The variables assigned to the object are An entity called an object .
For example:
Pointpoint=newPoint()
Point: class name
point: object name
new Point(): entity of the object
The reference to an object is the memory address where the object is stored.
Notice:
Avoid using empty objects when writing programs.
We call objects without entities empty objects. Empty objects cannot be used, that is, an empty object cannot be used to call methods to generate behaviors. If a null object is used in the program, a NullPointerException will occur when the program is running. Since objects can be assigned entities dynamically, the Java compiler does not check for null objects.
in conclusion:
If two objects declared by a class have the same reference, they have exactly the same variables, that is, entities. When the program uses a class to create two objects object1 and object2, their references are different.
In Java, for two objects object1 and object2 of the same class, the following assignment operations are allowed:
object1=object2;
In this way, the value stored in object1 will be the value of object2, that is, the reference of object2. Therefore, the variables, or entities, owned by object1 are exactly the same as object2.