Use of an array of Java objects

Source: Internet
Author: User

A class in Java belongs to a reference data type and, to an exact reference, a reference to a type object that is not of the type defined by the data type. References are used similar to pointers in C + +.

Java declares a reference to a class object and assigns the initial value: person p = null;

C + + defines a pointer to the class object and assigns the initial value: person* p = NULL;

The pointer p for a class object in C + + is not an object of the person class, it simply holds the starting address of a person class object in memory. A reference to a class object in Java has the same meaning as a class object pointer in C + +, where the address of the class object itself does not represent the starting address of the object, but the reference to the class object stores the object's starting address in memory.

In C + + defines a pointer array of class objects, the code can write:

person* p[3];p [0] = new person ();p [1] = new person ();p [2] = new Person ();

Defines a reference array of class objects in Java, which the code can write:

Person p[] = new Person[3];p [0] = new person ();p [1] = new person ();p [2] = new Person ();

Looking at the two examples above, it is found that a reference array that defines class objects in Java is very similar to the array of pointers that define class objects in C + +. Note: In Java, "new Person[3]" is not allocating 3 objects in memory, it is simply a reference to 3 objects, similar to the 3-object pointers in C + +.

Use of an array of Java objects

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.