Object and object instance

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.