Java record -33-array store object address

Source: Internet
Author: User

1. The address of the object is stored in the array.

public class ArrayTest3 {public static void main (string[] args) {i[] I = new i[2];        I[0] = new C ();    I[1] = new C (); }}interface I{}class C implements i{}

The above code can be compiled and run through, the same validation of the above conclusion: the array is stored in the object's address.

Regardless of what type of array is generated, the array holds the address of the object of that type, not the object of that type. If no object is assigned to the array, NULL is stored.

i[] i = new i[2]; The code is not the object that generates I, and the interface cannot generate the object. The I array can only hold the object address of the class that implements the I interface.

2. Arrays are also objects, and the following code compares two array objects that hold the same number with the Equals method, because it is two different objects.

public static void Main (string[] args) {int[] a = {-N-a};        Int[] B = {A-c};    System.out.println (A.equals (b)); }


Java record -33-array store object address

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.