What is the difference between objects and instances?
From a macro perspective, the difference between an object and an instance is that an object is an abstract representation of similar things, and an instance is an object specific. An object can be instantiated by many instances, an object is a model, and an instance is the final product produced according to this model. In fact, an object can instantiate n instances. Just like a product that can create multiple instances based on a model.
From the perspective of memory allocation, the object is stored in the heap, And the instance is stored in the storage stack. The instance is actually a reference of the object, that is, the pointer to the object.
Here is an image example. KFC has chicken wings. If you go to McDonald's to buy chicken wings, the chicken wings on the menu will be chicken wings. The chicken wings on the shelf will be the chicken wings, and the chicken wings you chew will be an example of chicken wings.
Class chicken wings
Chicken wings fried chicken wings (object)
Chicken wings fried chicken wings = new a fried chicken wings (a fried chicken wings is an object instance and an object)
In many cases, the format of instance of object is used. It's confusing.
I checked some information and analyzed it. Now I think this conclusion is easy to understand:
Class --> Object --> instance
Human beings are Class
Someone is an object
You are an instance
The instance itself is also an object.
This is what it shows.
String type
String STR is an object
String STR = "ABC"; "ABC" is an instance and an object.
In this way, the instance of STR, such as instance of object, can be interpreted as "ABC"
For the time being, I hope someone can come up with better understanding methods and insights...
The object refers to the reference name created in the stack.
An instance is a specific manifestation of the class created in the heap.
Generally, we declare an object and create an instance.
Declare an object like string s; it is just an empty variable name that is not referenced
Creating an instance is to call the class constructor new classconstrutor ();, which allocates specific space in the memory, but does not assign it to any reference, so you cannot call it.
Combining the two is a complete object creation process.
String S = new string ();
(Store the specific instance address in the object)