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