A question about Java variable Memory Allocation

Source: Internet
Author: User

Which of the following statements about declaration are true?

A. Declaration of primitive types such as Boolean, byte and so on does not allocate memory space for the variable.

B. Declaration of primitive types such as Boolean, byte and so on allocates memory space for the variable.

C. Declaration of nonprimitive types such as string, vector and so on does not allocate memory space for the object.

D. Declaration of nonprimitive types such as string, vector ans so on allocates memory space for the object.

1. Global variables:
When declaring a simple variable, the system will allocate space to it in the stack and give it a default value;
When declaring an object, the system also assigns a pointer to the object in the stack, but only points to null, rather than the memory space of the object.
2. Local variables:
Space will be allocated in the stack during the declaration (except that the object is still assigned a pointer to the object), and the system will not initialize the object by default, so it can only be used before initialization.

We can see from the above two points that BC is correct.

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.