The references to objects and objects in Java are two confusing notions of what kind of relationship a reference to an object and an object are.
First, the object
Learn the object-oriented language of the students can understand what the concept of the object, in Java all objects, in the code of the world, the object is a specific instance of class, such as a dog called Black is a specific instance of the dog, that is, a dog class object. A class is an abstract concept, and an object is a concrete instance of a class.
Ii. references to Objects
The application must be related to the object, and the question is what kind of management they have. In Java everything is an object, so when we write code, the operation is basically the object, right, then the problem? How do we manipulate the object?
Person person= Thenew person (" Zhang San "); // create an object and instantiate it Person Person2; // Create a reference to an object person2=New person (" John Doe "); // create an object and let the persons reference point to that object
This is how I create objects in the program, right we create an object by invoking the constructor of the class, which is the new person ("Zhang San") and the new person ("John Doe") in the code above, and these two words create an object.
So it is true that we created the object in memory, but how do we manipulate the two objects, such as: We want to set Zhang San age to 22 years old:
// set the age of Zhang San Person.setage (a);
Yes, we're using person, and it's obvious that this person is a reference to the object that we're manipulating "Zhang San", so it's easy to see what the reference is, and what the object and object references are related to. In "Think in Java"
It concludes that the reference to the object is a remote control of the object we are manipulating.
Java----references to objects and objects