Object Reference, Compiler

Source: Internet
Author: User

Object Reference, Compiler
1 public class Test {2 public static void main (String [] args) {3 Human aPerson = new Human (122 ); 4} 5 6} 7 class Human {8/* constructor */9 public Human (int h) {10 this. height = h; 11} 12/* accessor */13 public int GetHeight () {14 return this. height; 15} 16/* mutator */17 public void GrowHeight (int h) {18 this. height + = h; 19} 20 private int height; 21} View Code

 

APerson indicates that the reference object is stored in the memory stack.

But !!!

In Java, all (common) objects are stored on the stack. Therefore, the full meaning of the new Keyword is to create an object on the stack.

Objects of the basic type (primitive type), such as int and double, are stored on the stack. New is not required when we declare the basic type. Once declared, Java will directly store basic types of data on the stack. Therefore, the variable name of the basic type indicates the data itself, not the reference.

Reference Value assignment:

When we assign a reference value to another reference, we actually copy the object address. The two references point to the same object. For example, dummyPerson = aPerson; will cause:

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.