Java class storage features

Source: Internet
Author: User

In java, class variables store the object's memory address after initialization, not the object itself, that is, class variables point to the object's memory address. However, in java, you cannot see the memory address of the object. Generally, the "type name @ hexadecimal number" is not the memory address, it is only the hexadecimal representation of the hash code of the object. The java language itself does not provide any way to view the memory address. JVM is used to load class objects. For security and convenience, JVM memory management is transparent to Java application programmers. The following code gives you a general idea about how to store classes:

/*** Comments: class-type storage features * @ author plug-in name * Crete Time: 2013-10-5 **/public class Neicun {public static void main (String [] args) {Neicun [] n = new Neicun [3]; // an array is initialized and System is not initialized for Neicun. out. println (n [0]); // output null n [0] = new Neicun (); // call the constructor to initialize the System. out. println (n [0]); // n [0] points to the memory address, but the output is not the memory address, only the hex representation of the object's hash code. Neicun m = new Neicun (); System. out. println (m); // hexadecimal format of the hash code of the output object }}

The above Code not only illustrates the storage method of the class type, but also reflects another problem: when initializing an array of class types, it does not initialize each variable of the class type in the array, only the size of the array is confirmed, and the corresponding class type variables need to be initialized separately.

This article is from the blog "plug on the name of pigs", please be sure to keep this source http://zuohao1990.blog.51cto.com/6057850/1304854

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.